Pydub原始音频数据 [英] Pydub raw audio data

查看:288
本文介绍了Pydub原始音频数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Python 3.4中使用Pydub尝试检测某些音频文件的音高.

I'm using Pydub in Python 3.4 to try to detect the pitch of some audio files.

我有一个有效的音高检测算法(McLeod音高方法),对实时应用程序很健壮(我什至用它制作了一个Android音高检测应用程序:

I have a working pitch detection algorithm (McLeod Pitch Method), which is robust for real-time applications (I even made an Android pitch detection app with it: https://github.com/sevagh/Pitcha).

我的问题是,将算法应用于AudioSegment._data时,没有从算法中获得任何有意义的输出.

My issue is that I'm not getting any meaningful output from the algorithm when I apply it to AudioSegment._data.

代码:

from pydub import AudioSegment

sound = AudioSegment.from_wav(file="./8700hz.wav")

#sampling rate = sound.frame_rate = 44100hz
mpm = Mpm(sound.frame_rate, len(sound._data))
print(mpm.get_pitch(sound._data))

输出:

Pitch: 150.000002396

如果我从扬声器播放相同的wav文件,然后从麦克风上录制该文件,然后将算法应用于原始麦克风捕获(带符号的16位Little Endian PCM,44100Hz,单声道),则会得到正确的音调.

If I play the same wav file from my speakers, record it from my microphone and apply the algorithm on the raw microphone capture (signed 16-bit little endian PCM, 44100Hz, mono), I get the correct pitch.

AudioSegment._data是否不返回我的期望?

Does AudioSegment._data not return what I'm expecting?

推荐答案

sound._databytestring.我不确定输入Mpm会期望什么,但是您可能需要像这样将bytestring转换为array:

sound._data is a bytestring. I'm not sure what input Mpm expects, but you may need to convert the bytestring to an array like so:

import array
from pydub import AudioSegment
from pydub.utils import get_array_type

sound = AudioSegment.from_wav(file="./8700hz.wav")

bit_depth = sound.sample_width * 8
array_type = get_array_type(bit_depth)

numeric_array = array.array(array_type, sound._data)

这篇关于Pydub原始音频数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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