-
Notifications
You must be signed in to change notification settings - Fork 373
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How can I make pitch detection using Aubio works with PyAudio? #78
Comments
Hi @notalentgeek , Yes, alsa is linux only, that's correct. In your last snippet of code, the stream is opened with let us know how that works, best, piem |
I am not sure which part I need to multiply by I changed EDIT: Thanks for your response though!!!! |
FUCK YEAH IT IS WORKING!!!! import aubio
import numpy as num
import pyaudio
import wave
# PyAudio object.
p = pyaudio.PyAudio()
# Open stream.
stream = p.open(format=pyaudio.paFloat32,
channels=1, rate=44100, input=True,
frames_per_buffer=1024)
# Aubio's pitch detection.
pDetection = aubio.pitch("default", 2048,
2048//2, 44100)
# Set unit.
pDetection.set_unit("Hz")
pDetection.set_silence(-40)
while True:
data = stream.read(1024)
samples = num.fromstring(data,
dtype=aubio.float_type)
pitch = pDetection(samples)[0]
# Compute the energy (volume) of the
# current frame.
volume = num.sum(samples**2)/len(samples)
# Format the volume output so that at most
# it has six decimal numbers.
volume = "{:.6f}".format(volume)
print(pitch)
print(volume) Thanks! |
Great! I just added best, Paul |
@piem I have tried |
Breadcrumbs for future developers: I'm working on an application that will be handling signal from a bass guitar, and found that I had to up the buffer size significantly (up to 8192) in order to get a large enough window to reliably identify tones in the 40-60 Hz ranges. Thanks for making this code public though- this has saved me a TON of time and effort for figuring out the nuances of the aubio APIs! |
…tar is played. This loop was based off of the pitch detection method posted here: aubio/aubio#78 (comment)
Hello there! Some months ago I posted an issues here on how to get pitch detection with
alsaaudio
. I got the answer and it is working as what I want.However, I think (CMIIW)
alsaaudio
will not working in Windows platform. I saw another library called PyAudio which I assume works cross platform. Since, PyAudio is capable of listening audio from microphone and so doesalsaaudio
I thought I can easily changealsaaudio
with PyAudio.I use
alsaaudio
to feed data to Aubio pitch detector object. I tried to use the same method with PyAudio instead, but the pitch returned always 0.0 (I do notice there are difference in the sample fromalsaaudio
and PyAudio). Here are my codes.Here is my pitch detection codes with
alsaaudio
.Take a look at this part (the pitch detection converter into Aubio).
I tried to do the same with PyAudio here.
But the value of
pitch
are always 0.0.The text was updated successfully, but these errors were encountered: