Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions examples/020-twilio-media-streams-node/tests/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,21 @@ const TMP_MULAW = '/tmp/twilio_test.mulaw';
// We use 320 to match Twilio's actual observed frame size.
const CHUNK_SIZE = 320;

// Convert a known audio file to μ-law 8 kHz using ffmpeg.
// ffmpeg is pre-installed on all GitHub Actions ubuntu runners.
function ensureFfmpeg() {
try {
execSync('which ffmpeg', { stdio: 'pipe' });
} catch {
console.log('ffmpeg not found — installing via apt-get...');
execSync('sudo apt-get update -qq && sudo apt-get install -qq -y ffmpeg', {
stdio: 'pipe',
timeout: 60_000,
});
}
}

function prepareMulawAudio() {
ensureFfmpeg();

console.log('Downloading test audio...');
execSync(`curl -s -L -o "${TMP_WAV}" "${AUDIO_URL}"`, { stdio: 'pipe' });

Expand All @@ -44,8 +56,11 @@ function prepareMulawAudio() {
'-ar', '8000', '-ac', '1', '-f', 'mulaw', TMP_MULAW,
], { stdio: 'pipe' });

if (result.error) {
throw new Error(`ffmpeg spawn error: ${result.error.message}`);
}
if (result.status !== 0) {
throw new Error(`ffmpeg failed: ${result.stderr.toString().slice(0, 300)}`);
throw new Error(`ffmpeg failed: ${(result.stderr || Buffer.alloc(0)).toString().slice(0, 300)}`);
}

const audio = fs.readFileSync(TMP_MULAW);
Expand Down