Unstable API: This package is experimental for the moment. As we test it, we might make a few changes to the API and switch to a WebGPU-based backend in the future.
resampleTo16Khz()
Processes an audio File
or Blob
by decoding it, converting it to mono, and resampling it to a 16kHz Float32Array
. This prepares the audio data for use with the transcribe()
function.
This function operates in a browser environment as it relies on the Web Audio API (AudioContext
, OfflineAudioContext
) and FileReader
.
Arguments
file
The audio File
or Blob
object that you want to process. The function will attempt to decode the audio from common formats (e.g., WAV, MP3, Ogg) supported by the browser's Web Audio API.
onProgress?
A callback function that receives progress updates during the resampling process. The progress
value is a number between 0 and 1, where 0 indicates the start and 1 indicates completion.
logLevel?
Default: info
Type: 'trace' | 'verbose' | 'info' | 'warn' | 'error'
Optional. Determines the level of detail for logs printed to the console during the resampling process. Useful for debugging.
Return value
Promise<Float32Array>
This array contains the raw audio waveform data for a single channel (mono), sampled at 16kHz. This output is ready to be passed to the channelWaveform
argument of the transcribe()
function.
Behavior notes
- Browser environment: This function is intended for use in a browser environment due to its reliance on Web Audio APIs (
AudioContext
,OfflineAudioContext
) andFileReader
. - Audio decoding: It uses the browser's built-in audio decoding capabilities. The range of supported audio formats may vary slightly between browsers.
- Output format: The output is always a mono
Float32Array
at 16kHz, regardless of the input file's original channel count or sample rate.