【问题标题】:How to convert ulaw format file to wav format reactjsreactjs如何将ulaw格式文件转换为wav格式
【发布时间】:2021-06-12 19:15:57
【问题描述】:

我正在尝试在 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();

        })
}

【问题讨论】:

  • wav.fromScratch 通过 8000 非常低,应该在 44000 左右
  • @frozen 即使在将其设置为 44000 后,仍在播放其他一些噪音。

标签: javascript reactjs wav mu-law


【解决方案1】:

以下更改对我有用,仍然有一些噪音,但它可以产生 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();
        })
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-03-12
    • 1970-01-01
    • 1970-01-01
    • 2021-12-08
    • 2010-11-05
    • 1970-01-01
    相关资源
    最近更新 更多