in speech-to-text/functions/src/transcribe-audio.ts [128:198]
export async function transcodeToLinear16(
localTmpPath: string
): Promise<TranscodeAudioResult> {
const probeData: ffmpeg.FfprobeData = await probePromise(localTmpPath);
const warnings: WarningType[] = [];
logs.debug('probe data before transcription:', probeData);
const {streams} = probeData;
if (streams.length === 0) {
return {
status: Status.FAILURE,
type: FailureType.ZERO_STREAMS,
warnings,
};
}
if (streams.length !== 1) {
warnings.push(WarningType.MORE_THAN_ONE_STREAM);
}
if (streams[0].sample_rate == null) {
return {
status: Status.FAILURE,
type: FailureType.NULL_SAMPLE_RATE,
warnings,
};
}
if (streams[0].channels == null) {
return {
status: Status.FAILURE,
type: FailureType.NULL_CHANNELS,
warnings,
};
}
const localTranscodedPath = localTmpPath + TRANSCODE_TARGET_FILE_EXTENSION;
logs.debug('transcoding locally');
try {
await transcodeLocally({
inputPath: localTmpPath,
outputPath: localTranscodedPath,
});
} catch (error: unknown) {
const {err, stdout, stderr} = error as {
err: any;
stdout: string;
stderr: string;
};
return {
status: Status.FAILURE,
type: FailureType.FFMPEG_FAILURE,
warnings,
details: {
ffmpegError: err,
ffmpegStdout: stdout,
ffmpegStderr: stderr,
},
};
}
logs.debug('finished transcoding locally');
return {
status: Status.SUCCESS,
sampleRateHertz: streams[0].sample_rate,
audioChannelCount: streams[0].channels,
outputPath: localTranscodedPath,
warnings,
};
}