mirror of
https://github.com/langgenius/dify.git
synced 2026-07-21 02:28:30 +08:00
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Yansong Zhang <916125788@qq.com>
27 lines
656 B
TypeScript
27 lines
656 B
TypeScript
import { registerMp3Encoder } from '@mediabunny/mp3-encoder'
|
|
import { AudioBufferSource, BufferTarget, Mp3OutputFormat, Output } from 'mediabunny'
|
|
|
|
const AUDIO_BITRATE = 128_000
|
|
const AUDIO_SAMPLE_RATE = 16_000
|
|
|
|
export function createMp3Encoder() {
|
|
registerMp3Encoder()
|
|
|
|
const target = new BufferTarget()
|
|
const output = new Output({
|
|
format: new Mp3OutputFormat(),
|
|
target,
|
|
})
|
|
const audioSource = new AudioBufferSource({
|
|
bitrate: AUDIO_BITRATE,
|
|
codec: 'mp3',
|
|
transform: {
|
|
numberOfChannels: 1,
|
|
sampleRate: AUDIO_SAMPLE_RATE,
|
|
},
|
|
})
|
|
output.addAudioTrack(audioSource)
|
|
|
|
return { audioSource, output, target }
|
|
}
|