pyaudio

How to remove pops from concatented sound data in PyAudio

扶醉桌前 提交于 2019-11-30 18:27:44
问题 How do you remove "popping" and "clicking" sounds in audio constructed by concatenating sound tonal sound clips together? I have this PyAudio code for generating a series of tones: import time import math import pyaudio class Beeper(object): def __init__(self, **kwargs): self.bitrate = kwargs.pop('bitrate', 16000) self.channels = kwargs.pop('channels', 1) self._p = pyaudio.PyAudio() self.stream = self._p.open( format = self._p.get_format_from_width(1), channels = self.channels, rate = self

Playing .mp3 files with PyAudio

喜夏-厌秋 提交于 2019-11-30 15:47:30
Can pyaudio play .mp3 files? If yes, may I ask to write an example please. If no, what is the simplest way to convert .mp3 to .wav? I have tried to use PyDub, could get my .wav file, but when I try to play it with PyAudio I get following error: File "C:\Python33\lib\wave.py", line 130, in initfp raise Error('file does not start with RIFF id') wave.Error: file does not start with RIFF id With other .wav samples (which where not converted from mp3) if works well. I am using gTTS library to convert text to speech for my application. It creates short .mp3 files which I need to play then. Right now

Time between callback calls?

旧城冷巷雨未停 提交于 2019-11-30 15:24:06
I have a lab project that uses mainly PyAudio and to further understand its way of working I made some measurements, in this case time between callbacks (using callback mode). I timed it, and got an interesting result (@256 chunk size, 44.1k fs): 0.0099701;0.0000365;0.0000201;0.0201579 This pattern goes on and on. Between two longer calls, we have two shorter calls and sometimes the longer call is shorter (mind you I don't do anything else in the program than time the callbacks) . If we average this out we get our desired callback time: 1/44100 * 256 (roughly 5.8ms) Here is my measurement

How to handle in_data in Pyaudio callback mode?

戏子无情 提交于 2019-11-30 05:32:49
问题 I'm doing a project on Signal Processing in python. So far I've had a little succes with the nonblocking mode, but it gave a considerable amount of delay and clipping to the output. I want to implement a simple real-time audio filter using Pyaudio and Scipy.Signal, but in the callback function provided in the pyaudio example when I want to read the in_data I can't process it. Tried converting it in various ways but with no success. Here's a code I want to achieve(read data from mic, filter,

pyaudio installation on mac (python 3)

你说的曾经没有我的故事 提交于 2019-11-30 04:51:23
I first tried: pip install pyaudio but I was told that -bash: pip: command not found Then I tried: pip3 install pyaudio then i got: src/_portaudiomodule.c:29:10: fatal error: 'portaudio.h' file not found #include "portaudio.h" ^ 1 error generated. error: command '/usr/bin/clang' failed with exit status 1 ---------------------------------------- Command "/Library/Frameworks/Python.framework/Versions/3.4/bin/python3.4 -c "import setuptools, tokenize;__file__='/private/var/folders/77/gz1txkwj2z925vk6jrkx3wp80000gn/T/pip-build-43z_qk7o/pyaudio/setup.py';exec(compile(getattr(tokenize, 'open', open)

how to convert wav file to float amplitude

元气小坏坏 提交于 2019-11-30 02:28:30
so I asked everything in the title: I have a wav file (written by PyAudio from an input audio) and I want to convert it in float data corresponding of the sound level (amplitude) to do some fourier transformation etc... Anyone have an idea to convert WAV data to float? I have identified two decent ways of doing this. Method 1: using the wavefile module Use this method if you don't mind installing some extra libraries which involved a bit of messing around on my Mac but which was easy on my Ubuntu server. https://github.com/vokimon/python-wavefile import wavefile # returns the contents of the

What are chunks, samples and frames when using pyaudio

天涯浪子 提交于 2019-11-29 21:54:44
After going through the documentation of pyaudio and reading some other articles on the web, I am confused if my understanding is correct. This is the code for audio recording found on pyaudio's site: import pyaudio import wave CHUNK = 1024 FORMAT = pyaudio.paInt16 CHANNELS = 2 RATE = 44100 RECORD_SECONDS = 5 WAVE_OUTPUT_FILENAME = "output.wav" p = pyaudio.PyAudio() stream = p.open(format=FORMAT, channels=CHANNELS, rate=RATE, input=True, frames_per_buffer=CHUNK) print("* recording") frames = [] for i in range(0, int(RATE / CHUNK * RECORD_SECONDS)): data = stream.read(CHUNK) frames.append(data)

separate frequencies from music

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-29 17:58:06
i want to print separate frequency present in a music file. if freq amp is grater than threshold. then it will brinted. import pyaudio import wave import numpy as np chunk = 2048 wf = wave.open('/home/pi/music.wav', 'rb') swidth = wf.getsampwidth() RATE = wf.getframerate() window = np.blackman(chunk) p = pyaudio.PyAudio() stream = p.open(format = p.get_format_from_width(wf.getsampwidth()), channels = wf.getnchannels(), rate = RATE, output = True) data = wf.readframes(chunk) while len(data) != '': stream.write(data) indata = np.array(wave.struct.unpack("%dh"%(len(data)/swidth),\ data)) fftdata

get the amplitude data from an mp3 audio files using python

佐手、 提交于 2019-11-29 15:28:28
问题 I have an mp3 file and I want to basically plot the amplitude spectrum present in that audio sample. I know that we can do this very easily if we have a wav file. There are lot of python packages available for handling wav file format. However, I do not want to convert the file into wav format then store it and then use it. What I am trying to achieve is to get the amplitude of an mp3 file directly and even if I have to convert it into wav format, the script should do it on air during runtime

How do I get a list of my device's audio sample rates using PyAudio or PortAudio?

跟風遠走 提交于 2019-11-29 10:49:48
I'd like to query my audio device and get all its available sample rates. I'm using PyAudio 0.2, which runs on top of PortAudio v19, on an Ubuntu machine with Python 2.6. In the pyaudio distribution, test/system_info.py shows how to determine supported sample rates for devices. See the section that starts at line 49 . In short, you use the PyAudio.is_format_supported method, e.g. devinfo = p.get_device_info_by_index(1) # Or whatever device you care about. if p.is_format_supported(44100.0, # Sample rate input_device=devinfo['index'], input_channels=devinfo['maxInputChannels'], input_format