From 04059a66e6cbfcf8a5e92716bb67ab356e305123 Mon Sep 17 00:00:00 2001 From: Hayden Date: Thu, 3 Sep 2026 18:26:14 -0700 Subject: [PATCH] fix(examples): use the default audio recording input --- examples/audio/speech-to-text.ts | 2 +- tests/lib/audio-example-exit-status.test.ts | 16 +++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/examples/audio/speech-to-text.ts b/examples/audio/speech-to-text.ts index 01996b2a6c..27892eab75 100644 --- a/examples/audio/speech-to-text.ts +++ b/examples/audio/speech-to-text.ts @@ -5,7 +5,7 @@ const openai = new OpenAI(); async function main(): Promise { console.log('Recording for 5 seconds...'); - const response = await recordAudio({ timeout: 5000, device: 4 }); + const response = await recordAudio({ timeout: 5000 }); console.log('Transcribing...'); const transcription = await openai.audio.transcriptions.create({ diff --git a/tests/lib/audio-example-exit-status.test.ts b/tests/lib/audio-example-exit-status.test.ts index 70341f666c..08d66b313a 100644 --- a/tests/lib/audio-example-exit-status.test.ts +++ b/tests/lib/audio-example-exit-status.test.ts @@ -16,8 +16,10 @@ const audioTool = [ "const tool = require('node:path').basename(process.argv[1]);", "const failed = process.env.AUDIO_TOOL_FAILURE === 'true';", "if (tool === 'ffmpeg') {", - ' fs.writeFileSync(process.env.AUDIO_TRACE, JSON.stringify({ tool }));', - ' if (failed) process.exitCode = 47;', + " const input = process.argv[process.argv.indexOf('-i') + 1];", + ' fs.writeFileSync(process.env.AUDIO_TRACE, JSON.stringify({ tool, input }));', + // Model a machine with only input zero available. + " if (failed || ![':0', 'hw:0'].includes(input)) process.exitCode = 47;", " else process.stdout.write(Buffer.from(process.env.AUDIO_BYTES, 'hex'));", '} else {', ' const chunks = [];', @@ -160,9 +162,13 @@ describeOnUnix('audio executable examples', () => { if (!recording && scenario === 'HTTP rejection') { expect(existsSync(trace)).toBe(false); } else { - expect(JSON.parse(await readFile(trace, 'utf-8'))).toEqual( - recording ? { tool: 'ffmpeg' } : { tool: 'ffplay', audio: audio.toString('hex') }, - ); + const recorded = JSON.parse(await readFile(trace, 'utf-8')); + if (recording) { + expect(recorded.tool).toBe('ffmpeg'); + expect([':0', 'hw:0']).toContain(recorded.input); + } else { + expect(recorded).toEqual({ tool: 'ffplay', audio: audio.toString('hex') }); + } } if (scenario === 'success') { expect(result.stderr).toBe('');