wave

How to convert a wav file -> bytes-like object?

一个人想着一个人 提交于 2019-12-19 04:33:08
问题 I'm trying to programmatically analyse wav files with the audioop module of Python 3.5.1 to get channel, duration, sample rate, volumes etc. however I can find no documentation to describe how to convert a wav file to the 'fragment' parameter which must be a bytes-like object. Can anybody help? 回答1: file.read() returns a bytes object, so if you're just trying to get the contents of a file as bytes , something like the following would suffice: with open(filename, 'rb') as fd: contents = fd

Audio Frequencies in Python

空扰寡人 提交于 2019-12-18 06:57:33
问题 I'm writing a code to analyse a single audio frequency sung by a voice. I need a way to analyse the frequency of the note. Currently I am using PyAudio to record the audio file, which is stored as a .wav , and then immediately play it back. import numpy as np import pyaudio import wave # open up a wave wf = wave.open('file.wav', 'rb') swidth = wf.getsampwidth() RATE = wf.getframerate() # use a Blackman window window = np.blackman(chunk) # open stream p = pyaudio.PyAudio() stream = p.open

Reading *.wav files in Python

旧巷老猫 提交于 2019-12-17 02:34:13
问题 I need to analyze sound written in a .wav file. For that I need to transform this file into set of numbers (arrays, for example). I think I need to use the wave package. However, I do not know how exactly it works. For example I did the following: import wave w = wave.open('/usr/share/sounds/ekiga/voicemail.wav', 'r') for i in range(w.getnframes()): frame = w.readframes(i) print frame As a result of this code I expected to see sound pressure as function of time. In contrast I see a lot of

How to remove '\x' from a hex string in Python?

那年仲夏 提交于 2019-12-13 14:16:56
问题 I'm reading a wav audio file in Python using wave module. The readframe() function in this library returns frames as hex string. I want to remove \x of this string, but translate() function doesn't work as I want: >>> input = wave.open(r"G:\Workspace\wav\1.wav",'r') >>> input.readframes (1) '\xff\x1f\x00\xe8' >>> '\xff\x1f\x00\xe8'.translate(None,'\\x') '\xff\x1f\x00\xe8' >>> '\xff\x1f\x00\xe8'.translate(None,'\x') ValueError: invalid \x escape >>> '\xff\x1f\x00\xe8'.translate(None,r'\x') '

AVAudioPlayer refuses to play anything, but no error, etc

孤街醉人 提交于 2019-12-13 08:18:51
问题 This is the simplest possible AVAudioPlayer code, and it's just failing to play anything back. No errors, nothing in the console at all, the file is definitely being found as if I change the URL string to something which isn't there, I do get a crash. What am I doing wrong here? I've tried it with and without the delegate, as well as with and without prepareToPlay, and I can't get anything out. I've tried various sound files, too. Really tearing my hair out on this one! @implementation

Python Wave byte data

℡╲_俬逩灬. 提交于 2019-12-12 10:43:04
问题 I'm trying to read the data from a .wav file. import wave wr = wave.open("~/01 Road.wav", 'r') # sample width is 2 bytes # number of channels is 2 wave_data = wr.readframes(1) print(wave_data) This gives: b'\x00\x00\x00\x00' Which is the "first frame" of the song. These 4 bytes obviously correspond to the (2 channels * 2 byte sample width) bytes per frame, but what does each byte correspond to? In particular, I'm trying to convert it to a mono amplitude signal. 回答1: If you want to understand

Convert Recorded sound in iphone from one format to another say wav to mp3

江枫思渺然 提交于 2019-12-12 08:15:06
问题 I am trying to record some audio and convert them to other sound formats. I am using AVAudioRecorder class to record and these are the recording settings I used.. NSDictionary *recordSetting = [[NSMutableDictionary alloc] init]; [recordSetting setValue:[NSNumber numberWithInt:kAudioFormatLinearPCM] forKey:AVFormatIDKey];//kAudioFormatMicrosoftGSM,kAudioFormatLinearPCM [recordSetting setValue:[NSNumber numberWithFloat:8000] forKey:AVSampleRateKey]; [recordSetting setValue:[NSNumber

C++ - Play back a tone generated from a sinusoidal wave

三世轮回 提交于 2019-12-12 07:19:06
问题 Hey everyone, I'm currently trying to figure out how to play back a tone I have generated using a sinusoidal wave. Here's my code: #include <iostream> #include <OpenAL/al.h> #include <OpenAL/alc.h> #include <Math.h> using namespace std; int main (int argc, char * const argv[]) { int number = 0; int i, size; double const Pi=4*atan(1); cout << "Enter number of seconds:" << endl; scanf("%d", &number); size = 44100*number; unsigned char buffer [size]; //buffer array for(i = 0; i < size; i++){

Frequency & amplitue

孤人 提交于 2019-12-12 07:03:02
问题 I have a sql table which contains 2 columns: How to calculate the frequency of the highest amplitude wave ? (Each wave is of fixed frequency). Thank you 回答1: Try this select 1/Time as frequency from <table> order by amplitude desc limit 1 来源: https://stackoverflow.com/questions/32948673/frequency-amplitue

Linux and python: Combining multiple wave files to one wave file

随声附和 提交于 2019-12-12 05:59:26
问题 I am looking for a way that I can combine multiple wave files into one wave file using python and run it on linux. I don't want to use any add on other than the default shell command line and default python modules. For example, if I have a.wav and b.wav. I want to create a c.wav which start with the content from a.wav then b.wav. I've found wave module, that I can open a wave file and write into a new file. Since i'm really new in this audio world. I still can't figure out how to do it.