]> git.djapps.eu Git - pkg/ggml/sources/whisper.cpp/commitdiff
stream : add "--capture" option to select capture device (ref #10)
authorGeorgi Gerganov <redacted>
Sun, 30 Oct 2022 06:27:04 +0000 (08:27 +0200)
committerGeorgi Gerganov <redacted>
Sun, 30 Oct 2022 06:27:04 +0000 (08:27 +0200)
examples/stream/stream.cpp

index 276ad2432caa1fce08252f4b3c7e0004e3a10547..c39375a08fba1c7432eb2d51e423c5999d3fd40f 100644 (file)
@@ -35,10 +35,11 @@ std::string to_timestamp(int64_t t) {
 
 // command-line parameters
 struct whisper_params {
-    int32_t seed      = -1; // RNG seed, not used currently
-    int32_t n_threads = std::min(4, (int32_t) std::thread::hardware_concurrency());
-    int32_t step_ms   = 3000;
-    int32_t length_ms = 10000;
+    int32_t seed       = -1; // RNG seed, not used currently
+    int32_t n_threads  = std::min(4, (int32_t) std::thread::hardware_concurrency());
+    int32_t step_ms    = 3000;
+    int32_t length_ms  = 10000;
+    int32_t capture_id = -1;
 
     bool verbose              = false;
     bool translate            = false;
@@ -65,6 +66,8 @@ bool whisper_params_parse(int argc, char ** argv, whisper_params & params) {
             params.step_ms = std::stoi(argv[++i]);
         } else if (arg == "--length") {
             params.length_ms = std::stoi(argv[++i]);
+        } else if (arg == "-c" || arg == "--capture") {
+            params.capture_id = std::stoi(argv[++i]);
         } else if (arg == "-v" || arg == "--verbose") {
             params.verbose = true;
         } else if (arg == "--translate") {
@@ -109,6 +112,7 @@ void whisper_print_usage(int argc, char ** argv, const whisper_params & params)
     fprintf(stderr, "  -t N,     --threads N      number of threads to use during computation (default: %d)\n", params.n_threads);
     fprintf(stderr, "            --step N         audio step size in milliseconds (default: %d)\n", params.step_ms);
     fprintf(stderr, "            --length N       audio length in milliseconds (default: %d)\n", params.length_ms);
+    fprintf(stderr, "  -c ID,    --capture ID     capture device ID (default: -1)\n");
     fprintf(stderr, "  -v,       --verbose        verbose output\n");
     fprintf(stderr, "            --translate      translate from source language to english\n");
     fprintf(stderr, "  -kc,      --keep-context   keep text context from earlier audio (default: false)\n");
@@ -201,7 +205,7 @@ int main(int argc, char ** argv) {
 
     // init audio
 
-    if (!audio_sdl_init(-1)) {
+    if (!audio_sdl_init(params.capture_id)) {
         fprintf(stderr, "%s: audio_sdl_init() failed!\n", __func__);
         return 1;
     }