Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def gen_tone(frequency, duration=5.0, volume=0.5, fs=44100):
- p = PyAudio()
- # Sine wave
- # samples = (np.sin(2*np.pi*np.arange(fs*duration)*frequency/fs)).astype(np.float32)
- # Sawtooth wave. Can also be done with signal.sawtooth.
- # samples = (np.modf(np.arange(fs*duration)*frequency/fs)[0]*2.0-1.0).astype(np.float32)
- # DO NOT USE Triangle wave
- # t = np.linspace(0, duration, fs*duration)
- # samples = signal.sawtooth(2 * np.pi * t * frequency, width=0.5)
- stream = p.open(format=paFloat32,
- channels=1,
- rate=fs,
- output=True)
- stream.write(volume * samples)
- stream.stop_stream()
- stream.close()
- p.terminate()
Add Comment
Please, Sign In to add comment