@@ -115,8 +115,9 @@ int main(int argc, char **argv) {
115115 // std::cout << get_current_time().c_str() << ": Handling a message in thread: " << thread_id << std::endl;
116116 nlohmann::json response;
117117 if (opCode == uWS::OpCode::TEXT) {
118- // printf("%s: Received message on /paddlespeech/asr/streaming: %s\n", get_current_time().c_str(),std::string(message).c_str());
119118 // process text message
119+ printf (" %s: Received message on /paddlespeech/asr/streaming: %s\n " , get_current_time ().c_str (),std::string (message).c_str ());
120+
120121 try {
121122 auto jsonMsg = nlohmann::json::parse (message);
122123 std::string signal = jsonMsg[" signal" ];
@@ -134,12 +135,13 @@ int main(int argc, char **argv) {
134135 wavWriter.open (filename, WHISPER_SAMPLE_RATE, 16 , 1 );
135136 }
136137 if (signal == " end" ) {
138+ printf (" %s end\n " );
137139 wavWriter.close ();
138140// nlohmann::json response = {{"name",filename},{"signal", signal}};
139141 response = {{" name" , filename},
140142 {" signal" , signal}};
143+ printf (" %s:buffer size:%d\n " ,get_current_time ().c_str (),audioBuffer.size ());
141144 bool isOk = whisperService.process (audioBuffer.data (), audioBuffer.size ());
142- audioBuffer.clear ();
143145 if (isOk) {
144146 final_results = get_result (whisperService.ctx );
145147 response[" result" ] = final_results;
@@ -163,18 +165,22 @@ int main(int argc, char **argv) {
163165 // write to file
164166 wavWriter.write (pcm16.data (), size / 2 );
165167 // convert flost
166- for (int16_t sample: pcm16) {
167- float floatSample = static_cast <float >(sample);
168- audioBuffer.push_back (floatSample);
169- }
168+ std::vector<float > temp (size / 2 );
169+ std::transform (pcm16.begin (), pcm16.end (), temp.begin (), [](int16_t sample) {
170+ return static_cast <float >(sample) / 32768 .0f ;
171+ });
172+ // insert to audio_buffer
173+ audioBuffer.insert (audioBuffer.end (), temp.begin (), temp.end ());
174+
175+ printf (" %s:buffer size:%d\n " ,get_current_time ().c_str (),audioBuffer.size ());
170176 // 如果开启了VAD
171177 bool isOk;
172- printf (" %s: use_vad: %d\n " , get_current_time ().c_str (), params.audio .use_vad );
178+ // printf("%s: use_vad: %d\n", get_current_time().c_str(), params.audio.use_vad);
173179 if (params.audio .use_vad ) {
174180
175181 bool is_active = ::vad_simple (audioBuffer, WHISPER_SAMPLE_RATE, 1000 , params.audio .vad_thold ,
176182 params.audio .freq_thold , false );
177- printf (" %s: is_active: %d,is_last_active \n " , get_current_time ().c_str (), is_active, is_last_active);
183+ printf (" %s: is_active: %d,is_last_active %d \n " , get_current_time ().c_str (), is_active, is_last_active);
178184 if (!is_active && is_last_active) {
179185 is_last_active = false ;
180186 isOk = whisperService.process (audioBuffer.data (), audioBuffer.size ());
@@ -185,7 +191,7 @@ int main(int argc, char **argv) {
185191 } else {
186192 // asr
187193 isOk = whisperService.process (audioBuffer.data (), audioBuffer.size ());
188- audioBuffer.clear ();
194+ // audioBuffer.clear();
189195 }
190196 printf (" %s: is_ok: %d \n " , get_current_time ().c_str (), isOk);
191197 if (isOk) {
0 commit comments