PyAudio
is a python binding for PortAudio
. However, the api, to my humble opinion, is not so friendly to the programmer who has no deep or comprehensive knowledge about audio data. This package is yet another wrapper build upon PyAudio
in order to provide a friendly api.
from pyaudio_wrapper.audio_data import WavFileAudioData
wav_audio = WavFileAudioData("tests/data/my_voice.wav")
# Get the raw wav data in bytes string(hex format).
wav_audio.raw_wav_data
# duration of the audio file in milliseconds.
wav_audio.duration
# >>> 3008
# A numpy array of the wav audio data.
wav_audio.data
# Play the audio.
wav_audio.play()
# Play the audio from 500 millisecond to 1500 millisecond.
wav_audio.play(500, 1500)
# Segmentation of audio data
# segment from 500 millisecond to 1500 millisecond.
wav_segment = wav_audio[500:1500]
wav_segment.play() # just work!
from pyaudio_wrapper.analyse import AudioAnalysor
analysor = AudioAnalysor(wav_audio)
# plot the audio data.
analysor.plot()
analysor.show()
You can also use your mouse to select a segment of the data and then you will see the zoomed-in image of that segment in the subplot below. Moreover, you will hear the sound of that segment right away.
If the audio is stereo, you will see something like this:
coef = analysor.fft() # fast fourier transform.
# Or you can plot the spectrum.
analysor.plot_spectrum()
analysor.show()
If the audio is stereo, you will see something like this:
from pyaudio_wrapper.notes import *
(C + D).play() # play Do and Re for 0.5 sec, repsectively
happy.play() # One well-known song. : )
# My goal is to use this package to compose music in a simple way. XDD
from pyaudio_wrapper import Recorder
from pyaudio_wrapper.source import Microphone
recorder = Recorder() # Recording the sound from default microphone.
with Microphone() as source:
wav_audio = recorder.record(source)
wav_audio.play() # play out the audio.
wav_audio.data # an numpy array of this audio data
wav_audio.save('record.wav') # save the audio as a wav file.
git clone https://github.com/dboyliao/pyaudio_wrapper.git
cd pyaudio_wrapper
make install
# Run `make uninstall` if you want to uninstall this package.
# Before remove related files from your computer, there will
# be a prompt shows up asking you whether to remove the files
# from the directory shows up in the prompt message. Be sure
# that the directory is correct one or the uninstallation will
# just be skipped.
- The installation script works on my mac OS X 10.10.
- If you can not successfully install this package on OS X 10.10, you can try to re-install
python
withbrew
. That is, runbrew install python
. - I use
docker
to test installation scripts with ubuntu. It can successfully installportaudio
andpyaudio
but once you instantiatepyaudio.PyAudio
,ALSA
breaks. I don't know why by now.... - I don't know how to install
portaudio
andpyaudio
on Window. A little help here?
- This package is inspired by the
speech_recognition
module byUberi
. GitHub - PyAudio
- 24-bits Scipy
- 24-bits wave
- IOError
- plot, fft, fft2
- setup.py
- pyaudio_mac
- pydub
- avconv
- avconv install
- unknown format
- testing wav files