【问题标题】:.raw to .wav via pydub(AudioSegment) sounds noisy.raw 到 .wav 通过 pydub(AudioSegment) 听起来很吵
【发布时间】:2020-07-06 18:21:50
【问题描述】:

我想将 .raw 音频文件转换为 .wav 音频文件。所以,我使用下面的代码和 pydub AudioSegment

final = AudioSegment.from_file('input.raw', format='raw', frame_rate=8000, channels=1, sample_width=1).export('result.wav', format='wav')

顺便说一句,它的输出文件“result.wav”听起来很吵。实际上,我不确定“input.raw”文件的声音是否清晰(因为它是从 VoIP 电话的 RTP 数据包中获得的)。 所以,我的问题是,如果输入(.raw)文件没有崩溃,输出(.wav)文件是否有清晰的声音?我想知道是什么问题。崩溃的文件?或不正确的代码?

【问题讨论】:

    标签: python voip rtp pydub audiosegment


    【解决方案1】:

    我在尝试将 PCMU RAW 音频转换为 WAV 格式时遇到了类似的问题,我通过this issue on GitHub 联系了pydub 的作者,他的回复如下:

    pydub 假设文件名以 raw 结尾的任何文件都是原始波形。 而且也没有办法将 -ar 8000 注入转换 命令(告诉 ffmpeg 音频是每秒 8000 个样本)

    所以解决方法是手动打开文件,明确告诉pydub文件的格式是这样的:

    # open the file ourselves so that pydub doesn't try to inspect the file name
    with open('input.raw', 'rb') as raw_audio_f:
    
        # explicitly tell pydub the format for your file
        # use ffmpeg -i format | grep PCM to figure out what to string value to use
        sound = AudioSegment.from_file(raw_audio_f, format="mulaw")
    
        # override the default sample rate with the rate we know is correct
        sound.frame_rate = 8000
    
        # then export it
        sound.export('result.wav')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-02-18
      • 1970-01-01
      • 2019-11-21
      • 1970-01-01
      • 2016-10-27
      • 2018-06-11
      • 2020-10-16
      相关资源
      最近更新 更多