]> git.djapps.eu Git - pkg/ggml/sources/whisper.cpp/commitdiff
Adds support for stdin wav input
authorAlan <unknown>
Wed, 9 Nov 2022 18:24:06 +0000 (15:24 -0300)
committerGeorgi Gerganov <redacted>
Wed, 9 Nov 2022 18:37:23 +0000 (20:37 +0200)
examples/main/main.cpp

index 0bac6da4596442382303fa9d193070a32e080d4d..70580315769a5110b1dc67ee90433c3dd4a5f057 100644 (file)
@@ -454,9 +454,30 @@ int main(int argc, char ** argv) {
         std::vector<float> pcmf32;
         {
             drwav wav;
-            if (!drwav_init_file(&wav, fname_inp.c_str(), NULL)) {
-                fprintf(stderr, "%s: failed to open WAV file '%s' - check your input\n", argv[0], fname_inp.c_str());
-                whisper_print_usage(argc, argv, {});
+            
+            if (fname_inp == "-") {
+                std::vector<uint8_t> wav_data;
+                {
+                    uint8_t buf[1024];
+                    while (true)
+                    {
+                        const size_t n = fread(buf, 1, sizeof(buf), stdin);
+                        if (n == 0)
+                        {
+                            break;
+                        }
+                        wav_data.insert(wav_data.end(), buf, buf + n);
+                    }
+                }
+
+                if (drwav_init_memory(&wav, wav_data.data(), wav_data.size(), NULL) == false)
+                {
+                    fprintf(stderr, "error: failed to open WAV file from stdin\n");
+                    return 4;
+                }
+            }
+            else if (drwav_init_file(&wav, fname_inp.c_str(), NULL) == false) {
+                fprintf(stderr, "error: failed to open '%s' as WAV file\n", fname_inp.c_str());
                 return 4;
             }