实时将8kHz mulaw转换为16KHz PCM [英] Convert 8kHz mulaw to 16KHz PCM in real time

查看:203
本文介绍了实时将8kHz mulaw转换为16KHz PCM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的POC中,我收到了来自Twilio的8kHz mulaw流媒体对话,我想使用需要获得16KHz和PCM音频的Amazon Transcribe进行转录.

In my POC I'm receiving a conversation streaming from Twilio in 8kHz mulaw and I want to transcribe it using Amazon Transcribe that needs to get the audio in 16KHz and PCM.

我在此处如何转换文件,但在流式传输中却失败了...文件的代码为:

I found here how to convert a file but failed to do this in streaming... The code for a file is:

File sourceFile = new File("<Source_Path>.wav");
File targetFile = new File("<Destination_Path>.wav");
AudioInputStream sourceAudioInputStream = AudioSystem.getAudioInputStream(sourceFile);

AudioInputStream targetAudioInputStream=AudioSystem.getAudioInputStream(AudioFormat.Encoding.PCM_SIGNED, sourceAudioInputStream);
System.out.println("Sample Rate1 "+targetAudioInputStream.getFormat().getFrameRate());
AudioFormat targetFormat = new AudioFormat(new AudioFormat.Encoding("PCM_SIGNED"), 16000, 16, 1, 2, 8000, false);

AudioInputStream targetAudioInputStream1 = AudioSystem.getAudioInputStream(targetFormat, targetAudioInputStream);
System.out.println("Sample Rate "+targetAudioInputStream1.getFormat().getFrameRate());

try {
    AudioSystem.write(targetAudioInputStream1, AudioFileFormat.Type.WAVE, targetFile);
} catch (IOException e) {
    e.printStackTrace();
}

实际上Twilio给了我Base64(8KHz,mulaw)的播放负载,但我必须将其转换为16KHz,PCM.

Actually Twilio gives me a playload in Base64 (8KHz, mulaw) but I have to convert it to 16KHz, PCM.

推荐答案

您需要G.711解码器和音频重采样器.

You need a G.711 Decoder and Audio Resampler.

要遵循的步骤:

  1. 使用base64解码器解码收到的有效载荷.

  1. use base64 decoder to decode the Payload received.

使用此有效负载缓冲区并使用G.711解码器(mulaw到pcm)进行解码

use this payload buffer and decode using the G.711 decoder (mulaw to pcm)

输出需要提供给重采样器以进行上采样(8-> 16 KHz)

output of the G.711 decoder need to be given to the resampler for upsampling ( 8->16 KHz)

最后,所有缓冲区都已准备就绪,并且为PCM 16KHz.

Finally all the buffers are ready in PCM 16KHz.

这篇关于实时将8kHz mulaw转换为16KHz PCM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆