Skip to main content
warning

不稳定的 API:此软件包目前处于实验阶段。在测试过程中,我们可能会对 API 做一些更改,并在未来切换到基于 WebGPU 的后端。

resampleTo16Khz()

通过解码、转换为单声道并将音频 FileBlob 重采样为 16kHz Float32Array 来处理音频。这为使用 transcribe() 函数准备了音频数据。

🌐 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.

此功能在浏览器环境中运行,因为它依赖于 Web Audio API(AudioContextOfflineAudioContext)和 FileReader

🌐 This function operates in a browser environment as it relies on the Web Audio API (AudioContext, OfflineAudioContext) and FileReader.

参数

🌐 Arguments

file

你想要处理的音频 FileBlob 对象。该函数将尝试从浏览器的 Web Audio API 支持的常见格式(例如 WAV、MP3、Ogg)解码音频。

🌐 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?

在重采样过程中接收进度更新的回调函数。progress 值是介于 0 和 1 之间的数字,其中 0 表示开始,1 表示完成。

🌐 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?

默认:info

🌐 Default: info

类型: '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>

该数组包含单声道通道的原始音频波形数据,采样率为16kHz。此输出已准备好传递给transcribe()函数的channelWaveform参数。

🌐 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

  • 浏览器环境: 由于此函数依赖于 Web 音频 API(AudioContextOfflineAudioContext)和 FileReader,因此它旨在在浏览器环境中使用。
  • 音频解码: 它使用浏览器内置的音频解码功能。不同浏览器支持的音频格式范围可能略有差异。
  • 输出格式: 输出始终为16kHz的单声道 Float32Array,无论输入文件的原始声道数或采样率如何。

另请参阅

🌐 See also