Skip to content

Commit 5a9e426

Browse files
committed
stream : add "--capture" option to select capture device (ref #10)
1 parent eba62e0 commit 5a9e426

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

examples/stream/stream.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,11 @@ std::string to_timestamp(int64_t t) {
3535

3636
// command-line parameters
3737
struct whisper_params {
38-
int32_t seed = -1; // RNG seed, not used currently
39-
int32_t n_threads = std::min(4, (int32_t) std::thread::hardware_concurrency());
40-
int32_t step_ms = 3000;
41-
int32_t length_ms = 10000;
38+
int32_t seed = -1; // RNG seed, not used currently
39+
int32_t n_threads = std::min(4, (int32_t) std::thread::hardware_concurrency());
40+
int32_t step_ms = 3000;
41+
int32_t length_ms = 10000;
42+
int32_t capture_id = -1;
4243

4344
bool verbose = false;
4445
bool translate = false;
@@ -65,6 +66,8 @@ bool whisper_params_parse(int argc, char ** argv, whisper_params & params) {
6566
params.step_ms = std::stoi(argv[++i]);
6667
} else if (arg == "--length") {
6768
params.length_ms = std::stoi(argv[++i]);
69+
} else if (arg == "-c" || arg == "--capture") {
70+
params.capture_id = std::stoi(argv[++i]);
6871
} else if (arg == "-v" || arg == "--verbose") {
6972
params.verbose = true;
7073
} else if (arg == "--translate") {
@@ -109,6 +112,7 @@ void whisper_print_usage(int argc, char ** argv, const whisper_params & params)
109112
fprintf(stderr, " -t N, --threads N number of threads to use during computation (default: %d)\n", params.n_threads);
110113
fprintf(stderr, " --step N audio step size in milliseconds (default: %d)\n", params.step_ms);
111114
fprintf(stderr, " --length N audio length in milliseconds (default: %d)\n", params.length_ms);
115+
fprintf(stderr, " -c ID, --capture ID capture device ID (default: -1)\n");
112116
fprintf(stderr, " -v, --verbose verbose output\n");
113117
fprintf(stderr, " --translate translate from source language to english\n");
114118
fprintf(stderr, " -kc, --keep-context keep text context from earlier audio (default: false)\n");
@@ -201,7 +205,7 @@ int main(int argc, char ** argv) {
201205

202206
// init audio
203207

204-
if (!audio_sdl_init(-1)) {
208+
if (!audio_sdl_init(params.capture_id)) {
205209
fprintf(stderr, "%s: audio_sdl_init() failed!\n", __func__);
206210
return 1;
207211
}

0 commit comments

Comments
 (0)