Split the input audio in chunks and process each chunk separately using whisper_full_with_state() Result is stored in the default state of the context Not thread safe if executed in parallel on the same context. It seems this approach can offer some speedup in some cases. However, the transcription accuracy can be worse at the beginning and end of each chunk.
| 414 | // this approach can offer some speedup in some cases. However, the |
| 415 | // transcription accuracy can be worse at the beginning and end of each chunk. |
| 416 | int Context::full_parallel(Params params, std::vector<float> data, |
| 417 | int num_processor) { |
| 418 | |
| 419 | if (wstate != nullptr && num_processor > 1) { |
| 420 | // NOTE: need to point the current state for the context to work. |
| 421 | wctx->state = wstate; |
| 422 | } |
| 423 | |
| 424 | if (num_processor == 1) { |
| 425 | return this->full(params, data); |
| 426 | } |
| 427 | |
| 428 | Params copy = params.copy_for_full(*this); |
| 429 | int ret = whisper_full_parallel(wctx, *copy.get(), data.data(), data.size(), |
| 430 | num_processor); |
| 431 | |
| 432 | if (ret == -1) { |
| 433 | RAISE_RUNTIME_ERROR( |
| 434 | "Failed to compute log mel spectrogram with 'speed_up=True'."); |
| 435 | } else if (ret == -2) { |
| 436 | RAISE_RUNTIME_ERROR("Failed to compute log mel spectrogram with."); |
| 437 | } else if (ret == -3) { |
| 438 | RAISE_RUNTIME_ERROR("Failed to auto-detect language."); |
| 439 | } else if (ret == -5) { |
| 440 | RAISE_RUNTIME_ERROR( |
| 441 | STREAM_CAST(std::stringstream() |
| 442 | << "audio_ctx is larger than maximum allowed (" |
| 443 | << std::to_string(params.get()->audio_ctx) << " > " |
| 444 | << this->n_audio_ctx() << ").") |
| 445 | .str()); |
| 446 | } else if (ret == -6) { |
| 447 | RAISE_RUNTIME_ERROR("Failed to encode."); |
| 448 | } else if (ret == -7 || ret == -8) { |
| 449 | RAISE_RUNTIME_ERROR("Failed to decode."); |
| 450 | } else { |
| 451 | return ret; |
| 452 | } |
| 453 | }; |
| 454 | |
| 455 | // Number of generated text segments |
| 456 | // A segment can be a few words, a sentence, or even a paragraph. |
no test coverage detected