收藏
回答

腾讯云语音合成服务(流式)返回是二进制 pcm 音频,在小程序中播放异常?

腾讯云语音合成服务(流式)返回是二进制 pcm 音频,在小程序中用source.buffer 播放会刺啦刺啦的,调整采样率在开发者工具正常,但手机预览会有问题

主要代码

const floatData = this.bufferQueue.shift();


const audioBuffer = this.audioContext.createBuffer(

  1,

  floatData.length,

  16000

);



audioBuffer.copyToChannel(floatData, 0); // 意思是将数据复制到音频缓冲区的第一个通道


const source = this.audioContext.createBufferSource(); //

source.buffer = audioBuffer;

// 播放images/

// 连接到增益节点

source.connect(this.gainNode);


this.isBuffering = true;

this.isPlaying = true;

this._callbacks.onPlaying?.(true);


source.onended = () => {

  this.isBuffering = false;

  this.checkAndNotifyComplete();


  if (this.bufferQueue.length > 0) {

    this.playNextBuffer();

  }

};


source.start(0);

回答关注问题邀请回答
收藏

1 个回答

  • 智能回答 智能回答 该问答由AI生成
    04-04
    有用
登录 后发表内容