From 5a9e4260a64ce3256ece1323aa6049d31b933626 Mon Sep 17 00:00:00 2001 From: Georgi Gerganov Date: Sun, 30 Oct 2022 08:27:04 +0200 Subject: [PATCH] stream : add "--capture" option to select capture device (ref #10) --- examples/stream/stream.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/examples/stream/stream.cpp b/examples/stream/stream.cpp index 276ad24..c39375a 100644 --- a/examples/stream/stream.cpp +++ b/examples/stream/stream.cpp @@ -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; }