0

我正在尝试在 reactjs 中播放 .ulaw 格式,但没有找到任何直接播放 ulaw 文件的方法。所以我尝试使用 wavfile 插件将 ulaw 格式转换为 wav。但转换后它播放不同的噪音,我无法确定实际错误在哪里。

ulaw文件详细信息:

采样率 8000

比特率 64

单声道

import voice from '../src/app/components/voice.ulaw'
const WaveFile = require('wavefile').WaveFile;

let wav = new WaveFile();


const playUlawFile = () => {
    fetch(voice)
        .then(r => r.text())
        .then(text =>  Buffer.from(text, "utf-8").toString("base64"))
        .then(result =>{
            wav.bitDepth = '128000'
            wav.fromScratch(1, 8000, '64', result);
            wav.fromMuLaw();
            wav.toSampleRate(64000);
        return wav;

        }).then(wav => {
            audio = new Audio(wav.toDataURI())
            return audio;
        }).then(audio => {
            audio.play();

        })
}
4

1 回答 1

0

以下更改对我有用,仍然有一些噪音,但它可以产生 80% 匹配的声音。

const readFile = () => {
    fetch(voice)
        .then(r => r.text())
        .then(text =>  btoa(unescape(encodeURIComponent(text)))         )
        .then(result =>{
            wav.fromScratch(1, 18000, '8m', Buffer.from(result, "base64"));
            wav.fromMuLaw(32);
           wav.toSampleRate(64000, {method: "sinc"});
           return wav;
        }).then(wav => {
            audio = new Audio(wav.toDataURI())
            return audio;
        }).then(audio => {
            audio.play();
        })
}
于 2021-06-14T18:00:51.530 回答