|
24 | 24 | #include <io.h> |
25 | 25 | #endif |
26 | 26 |
|
| 27 | +#ifdef WHISPER_FFMPEG |
| 28 | +// as implemented in ffmpeg_trancode.cpp only embedded in common lib if whisper built with ffmpeg support |
| 29 | +extern bool ffmpeg_decode_audio(const std::string & ifname, std::vector<uint8_t> & wav_data); |
| 30 | +#endif |
| 31 | + |
27 | 32 | // Function to check if the next argument exists |
28 | 33 | std::string get_next_arg(int& i, int argc, char** argv, const std::string& flag, gpt_params& params) { |
29 | 34 | if (i + 1 < argc && argv[i + 1][0] != '-') { |
@@ -637,7 +642,7 @@ bool is_wav_buffer(const std::string buf) { |
637 | 642 |
|
638 | 643 | bool read_wav(const std::string & fname, std::vector<float>& pcmf32, std::vector<std::vector<float>>& pcmf32s, bool stereo) { |
639 | 644 | drwav wav; |
640 | | - std::vector<uint8_t> wav_data; // used for pipe input from stdin |
| 645 | + std::vector<uint8_t> wav_data; // used for pipe input from stdin or ffmpeg decoding output |
641 | 646 |
|
642 | 647 | if (fname == "-") { |
643 | 648 | { |
@@ -670,8 +675,19 @@ bool read_wav(const std::string & fname, std::vector<float>& pcmf32, std::vector |
670 | 675 | } |
671 | 676 | } |
672 | 677 | else if (drwav_init_file(&wav, fname.c_str(), nullptr) == false) { |
| 678 | +#if defined(WHISPER_FFMPEG) |
| 679 | + if (ffmpeg_decode_audio(fname, wav_data) != 0) { |
| 680 | + fprintf(stderr, "error: failed to ffmpeg decode '%s' \n", fname.c_str()); |
| 681 | + return false; |
| 682 | + } |
| 683 | + if (drwav_init_memory(&wav, wav_data.data(), wav_data.size(), nullptr) == false) { |
| 684 | + fprintf(stderr, "error: failed to read wav data as wav \n"); |
| 685 | + return false; |
| 686 | + } |
| 687 | +#else |
673 | 688 | fprintf(stderr, "error: failed to open '%s' as WAV file\n", fname.c_str()); |
674 | 689 | return false; |
| 690 | +#endif |
675 | 691 | } |
676 | 692 |
|
677 | 693 | if (wav.channels != 1 && wav.channels != 2) { |
|
0 commit comments