@@ -115,8 +115,9 @@ int main(int argc, char **argv) {
115
115
// std::cout << get_current_time().c_str() << ": Handling a message in thread: " << thread_id << std::endl;
116
116
nlohmann::json response;
117
117
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());
119
118
// 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
+
120
121
try {
121
122
auto jsonMsg = nlohmann::json::parse (message);
122
123
std::string signal = jsonMsg[" signal" ];
@@ -134,12 +135,13 @@ int main(int argc, char **argv) {
134
135
wavWriter.open (filename, WHISPER_SAMPLE_RATE, 16 , 1 );
135
136
}
136
137
if (signal == " end" ) {
138
+ printf (" %s end\n " );
137
139
wavWriter.close ();
138
140
// nlohmann::json response = {{"name",filename},{"signal", signal}};
139
141
response = {{" name" , filename},
140
142
{" signal" , signal}};
143
+ printf (" %s:buffer size:%d\n " ,get_current_time ().c_str (),audioBuffer.size ());
141
144
bool isOk = whisperService.process (audioBuffer.data (), audioBuffer.size ());
142
- audioBuffer.clear ();
143
145
if (isOk) {
144
146
final_results = get_result (whisperService.ctx );
145
147
response[" result" ] = final_results;
@@ -163,18 +165,22 @@ int main(int argc, char **argv) {
163
165
// write to file
164
166
wavWriter.write (pcm16.data (), size / 2 );
165
167
// 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 ());
170
176
// 如果开启了VAD
171
177
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);
173
179
if (params.audio .use_vad ) {
174
180
175
181
bool is_active = ::vad_simple (audioBuffer, WHISPER_SAMPLE_RATE, 1000 , params.audio .vad_thold ,
176
182
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);
178
184
if (!is_active && is_last_active) {
179
185
is_last_active = false ;
180
186
isOk = whisperService.process (audioBuffer.data (), audioBuffer.size ());
@@ -185,7 +191,7 @@ int main(int argc, char **argv) {
185
191
} else {
186
192
// asr
187
193
isOk = whisperService.process (audioBuffer.data (), audioBuffer.size ());
188
- audioBuffer.clear ();
194
+ // audioBuffer.clear();
189
195
}
190
196
printf (" %s: is_ok: %d \n " , get_current_time ().c_str (), isOk);
191
197
if (isOk) {
0 commit comments