]> git.djapps.eu Git - pkg/ggml/sources/ggml/commitdiff
server : implement "verbose_json" format with token details (whisper/1781)
authorRyan Hitchman <redacted>
Thu, 18 Jan 2024 20:58:42 +0000 (13:58 -0700)
committerGeorgi Gerganov <redacted>
Sat, 27 Jan 2024 15:33:43 +0000 (17:33 +0200)
* examples/server: implement "verbose_json" format with token details.

This is intended to mirror the format of openai's Python
whisper.transcribe() return values.

* server: don't write WAV to a temporary file if not converting

* server: use std::lock_guard instead of manual lock/unlock

examples/common.cpp
examples/common.h

index 603c655a184c745c0332351d729c2530afbe5772..8404e00e09e6e36383a2b4234c842ed39bf2b1ab 100644 (file)
@@ -639,6 +639,12 @@ bool read_wav(const std::string & fname, std::vector<float>& pcmf32, std::vector
 
         fprintf(stderr, "%s: read %zu bytes from stdin\n", __func__, wav_data.size());
     }
+    else if (fname.size() > 256 || fname.size() > 40 && fname.substr(0, 4) == "RIFF" && fname.substr(8, 4) == "WAVE") {
+        if (drwav_init_memory(&wav, fname.c_str(), fname.size(), nullptr) == false) {
+            fprintf(stderr, "error: failed to open WAV file from fname buffer\n");
+            return false;
+        }
+    }
     else if (drwav_init_file(&wav, fname.c_str(), nullptr) == false) {
         fprintf(stderr, "error: failed to open '%s' as WAV file\n", fname.c_str());
         return false;
index 54f0b00d0ef41fd4e65c969663536c85bcb7680c..aebeb0cd4f57aa5c3177fe6bdb14c3779e366bff 100644 (file)
@@ -136,6 +136,7 @@ gpt_vocab::id gpt_sample_top_k_top_p_repeat(
 //
 
 // Read WAV audio file and store the PCM data into pcmf32
+// fname can be a buffer of WAV data instead of a filename
 // The sample rate of the audio must be equal to COMMON_SAMPLE_RATE
 // If stereo flag is set and the audio has 2 channels, the pcmf32s will contain 2 channel PCM
 bool read_wav(