Spaces:
Running
Running
stream : print warning when processing is not fast enough
Browse files- stream.cpp +14 -5
stream.cpp
CHANGED
|
@@ -215,6 +215,8 @@ int main(int argc, char ** argv) {
|
|
| 215 |
std::vector<float> pcmf32(n_samples_30s, 0.0f);
|
| 216 |
std::vector<float> pcmf32_old;
|
| 217 |
|
|
|
|
|
|
|
| 218 |
// print some info about the processing
|
| 219 |
{
|
| 220 |
printf("\n");
|
|
@@ -234,6 +236,8 @@ int main(int argc, char ** argv) {
|
|
| 234 |
params.language.c_str(),
|
| 235 |
params.translate ? "translate" : "transcribe",
|
| 236 |
params.no_timestamps ? 0 : 1);
|
|
|
|
|
|
|
| 237 |
printf("\n");
|
| 238 |
}
|
| 239 |
|
|
@@ -256,10 +260,16 @@ int main(int argc, char ** argv) {
|
|
| 256 |
}
|
| 257 |
}
|
| 258 |
|
| 259 |
-
// process
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 260 |
while (SDL_GetQueuedAudioSize(g_dev_id_in) < n_samples*sizeof(float)) {
|
| 261 |
SDL_Delay(1);
|
| 262 |
}
|
|
|
|
| 263 |
const int n_samples_new = SDL_GetQueuedAudioSize(g_dev_id_in)/sizeof(float);
|
| 264 |
|
| 265 |
// take one second from previous iteration
|
|
@@ -300,9 +310,7 @@ int main(int argc, char ** argv) {
|
|
| 300 |
|
| 301 |
// print result;
|
| 302 |
{
|
| 303 |
-
|
| 304 |
-
printf("\33[2K\r");
|
| 305 |
-
}
|
| 306 |
|
| 307 |
const int n_segments = whisper_full_n_segments(ctx);
|
| 308 |
for (int i = 0; i < n_segments; ++i) {
|
|
@@ -321,7 +329,8 @@ int main(int argc, char ** argv) {
|
|
| 321 |
}
|
| 322 |
|
| 323 |
++n_iter;
|
| 324 |
-
|
|
|
|
| 325 |
printf("\n");
|
| 326 |
|
| 327 |
pcmf32_old.clear();
|
|
|
|
| 215 |
std::vector<float> pcmf32(n_samples_30s, 0.0f);
|
| 216 |
std::vector<float> pcmf32_old;
|
| 217 |
|
| 218 |
+
const int n_new_line = params.length_ms / params.step_ms - 1;
|
| 219 |
+
|
| 220 |
// print some info about the processing
|
| 221 |
{
|
| 222 |
printf("\n");
|
|
|
|
| 236 |
params.language.c_str(),
|
| 237 |
params.translate ? "translate" : "transcribe",
|
| 238 |
params.no_timestamps ? 0 : 1);
|
| 239 |
+
|
| 240 |
+
printf("%s: n_new_line = %d\n", __func__, n_new_line);
|
| 241 |
printf("\n");
|
| 242 |
}
|
| 243 |
|
|
|
|
| 260 |
}
|
| 261 |
}
|
| 262 |
|
| 263 |
+
// process new audio
|
| 264 |
+
if (n_iter > 0 && SDL_GetQueuedAudioSize(g_dev_id_in) > 2*n_samples*sizeof(float)) {
|
| 265 |
+
fprintf(stderr, "\n\n%s: WARNING: cannot process audio fast enough, dropping audio ...\n\n", __func__);
|
| 266 |
+
SDL_ClearQueuedAudio(g_dev_id_in);
|
| 267 |
+
}
|
| 268 |
+
|
| 269 |
while (SDL_GetQueuedAudioSize(g_dev_id_in) < n_samples*sizeof(float)) {
|
| 270 |
SDL_Delay(1);
|
| 271 |
}
|
| 272 |
+
|
| 273 |
const int n_samples_new = SDL_GetQueuedAudioSize(g_dev_id_in)/sizeof(float);
|
| 274 |
|
| 275 |
// take one second from previous iteration
|
|
|
|
| 310 |
|
| 311 |
// print result;
|
| 312 |
{
|
| 313 |
+
printf("\33[2K\r");
|
|
|
|
|
|
|
| 314 |
|
| 315 |
const int n_segments = whisper_full_n_segments(ctx);
|
| 316 |
for (int i = 0; i < n_segments; ++i) {
|
|
|
|
| 329 |
}
|
| 330 |
|
| 331 |
++n_iter;
|
| 332 |
+
|
| 333 |
+
if ((n_iter % n_new_line) == 0) {
|
| 334 |
printf("\n");
|
| 335 |
|
| 336 |
pcmf32_old.clear();
|