3
3
#include " stream_components_params.h"
4
4
#include " stream_components_output.h"
5
5
#include " stream_components_service.h"
6
+ // #include "json.hpp"
6
7
7
8
using namespace stream_components ;
8
9
@@ -101,6 +102,8 @@ int main(int argc, char **argv) {
101
102
102
103
// Compute derived parameters
103
104
params.initialize ();
105
+ // output params
106
+ printf (" vad:%d\n " , params.audio .use_vad );
104
107
105
108
// Check parameters
106
109
if (params.service .language != " auto" && whisper_lang_id (params.service .language .c_str ()) == -1 ) {
@@ -115,7 +118,7 @@ int main(int argc, char **argv) {
115
118
// Instantiate the service
116
119
struct whisper_context_params cparams;
117
120
cparams.use_gpu = params.service .use_gpu ;
118
- stream_components::WhisperService whisperService (params.service , params.audio ,cparams);
121
+ stream_components::WhisperService whisperService (params.service , params.audio , cparams);
119
122
120
123
// Print the 'header'...
121
124
WhisperStreamOutput::to_json (std::cout, params.service , whisperService.ctx );
@@ -133,12 +136,27 @@ int main(int argc, char **argv) {
133
136
// get next microphone section
134
137
auto pcmf32 = microphone.get_next ();
135
138
139
+ // process
140
+ bool isOk = whisperService.process (pcmf32.data (), pcmf32.size ());
141
+ printf (" isOk:%d\n " , isOk);
136
142
// get the whisper output
137
- const WhisperOutputPtr &outputPtr = whisperService.process (pcmf32.data (), pcmf32.size ());
138
- // write the output as json to stdout (for this example)
139
- if (outputPtr) {
140
- outputPtr->transcription_to_json (std::cout);
143
+ if (isOk) {
144
+ // WhisperOutputPtr outputPtr = std::make_shared<WhisperStreamOutput>(whisperService.ctx, params.service);
145
+ // // write the output as json to stdout (for this example)
146
+ // if (outputPtr) {
147
+ // outputPtr->transcription_to_json(std::cout);
148
+ // }
149
+ const int n_segments = whisper_full_n_segments (whisperService.ctx );
150
+ printf (" n_segments:%d\n " , n_segments);
151
+ for (int i = 0 ; i < n_segments; ++i) {
152
+ const char *text = whisper_full_get_segment_text (whisperService.ctx , i);
153
+ const int64_t t0 = whisper_full_get_segment_t0 (whisperService.ctx , i);
154
+ const int64_t t1 = whisper_full_get_segment_t1 (whisperService.ctx , i);
155
+ printf (" %lld-->%lld:%s\n " , t0, t1, text);
156
+ }
157
+
141
158
}
159
+
142
160
}
143
161
std::cout << " EXITED MAIN LOOP" << std::endl;
144
162
return 0 ;
0 commit comments