Play WAV file in Python

You can use PyAudio. An example here on my Linux it works: #!usr/bin/env python #coding=utf-8 import pyaudio import wave #define stream chunk chunk = 1024 #open a wav format music f = wave.open(r”/usr/share/sounds/alsa/Rear_Center.wav”,”rb”) #instantiate PyAudio p = pyaudio.PyAudio() #open stream stream = p.open(format = p.get_format_from_width(f.getsampwidth()), channels = f.getnchannels(), rate = f.getframerate(), output = True) #read … Read more

Note onset detection

Here is a graphic that illustrates the threshold approach to note onset detection: This image shows a typical WAV file with three discrete notes played in succession. The red line represents a chosen signal threshold, and the blue lines represent note start positions returned by a simple algorithm that marks a start when the signal … Read more

How to split a .wav file into multiple .wav files?

This is a python code snippet that I use for splitting files as per necessity. I use the pydub library from https://github.com/jiaaro/pydub. You can modify the snippet to suit your requirement. from pydub import AudioSegment t1 = t1 * 1000 #Works in milliseconds t2 = t2 * 1000 newAudio = AudioSegment.from_wav(“oldSong.wav”) newAudio = newAudio[t1:t2] newAudio.export(‘newSong.wav’, … Read more

Slow start for AVAudioPlayer the first time a sound is played

The delay seems to be related to instantiating AVAudioPlayer for the first time. If I load any audio, run [audioPlayer prepareToPlay] and then immediately release it, the load times for all of my other audio is very close to imperceptible. So now I’m doing that in applicationDidFinishLaunching and everything else runs well. I can’t find … Read more

Generating sine wave sound in Python

Version with numpy: import time import numpy as np import pyaudio p = pyaudio.PyAudio() volume = 0.5 # range [0.0, 1.0] fs = 44100 # sampling rate, Hz, must be integer duration = 5.0 # in seconds, may be float f = 440.0 # sine frequency, Hz, may be float # generate samples, note conversion … Read more

Sound generation / synthesis with python?

I was looking for the same thing, In the end, I wrote this code which is working fine. import math #import needed modules import pyaudio #sudo apt-get install python-pyaudio PyAudio = pyaudio.PyAudio #initialize pyaudio #See https://en.wikipedia.org/wiki/Bit_rate#Audio BITRATE = 16000 #number of frames per second/frameset. FREQUENCY = 500 #Hz, waves per second, 261.63=C4-note. LENGTH = 1 … Read more

Is there a public way to force MPNowPlayingInfoCenter to show podcast controls?

OK so I had a bit of time on my hands and so I followed the breadcrumb.… This is what I found. Include the MediaPlayer framework and get hold of the RemoteCommandCenter: MPRemoteCommandCenter *rcc = [MPRemoteCommandCenter sharedCommandCenter]; then if you wanted to set the skip controls as per Overcast you can do the following: MPSkipIntervalCommand … Read more

Python: Making a beep noise

On Windows, if you want to just make the computer make a beep sound: import winsound frequency = 2500 # Set Frequency To 2500 Hertz duration = 1000 # Set Duration To 1000 ms == 1 second winsound.Beep(frequency, duration) The winsound.Beep() can be used wherever you want the beep to occur.

Sound overlapping with multiple button presses

Declare your AVAudioPlayer in the header the viewController ( don’t alloc a new one each time you play a sound). That way you will have a pointer you can use in a StopAudio method. @interface myViewController : UIViewController <AVAudioPlayerDelegate> { AVAudioPlayer *theAudio; } @property (nonatomic, retain) AVAudioPlayer *theAudio; @end @implementation myViewController @synthesize theAudio; – (void)dealloc … Read more