Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python generate sine wave pyaudio

import pyaudio
import numpy as np

p = pyaudio.PyAudio()

volume = 0.5     # range [0.0, 1.0]
fs = 44100       # sampling rate, Hz, must be integer
duration = 1.0   # in seconds, may be float
f = 440.0        # sine frequency, Hz, may be float

# generate samples, note conversion to float32 array
samples = (np.sin(2*np.pi*np.arange(fs*duration)*f/fs)).astype(np.float32)

# for paFloat32 sample values must be in range [-1.0, 1.0]
stream = p.open(format=pyaudio.paFloat32,
                channels=1,
                rate=fs,
                output=True)

# play. May repeat with different volume values (if done interactively) 
stream.write(volume*samples)

stream.stop_stream()
stream.close()

p.terminate()
Comment

PREVIOUS NEXT
Code Example
Python :: filter numbers with bounds filter_bounds python 
Python :: python move all txt files 
Python :: ffff in decimal python 
Python :: how to save date in cookie Python 
Python :: python cv2 blob detection seg fault 
Python :: Freqtrade - Informative Pairs 
Python :: round up 
Python :: most efficient fibonacci number algorithm 
Python :: abstract user in django 
Python :: matruzen rechner python 
Python :: tanimoto coefficient rdkit 
Python :: python which __divs__ are there 
Python :: Random Remarks Example in python 
Python :: python to pseudo code converter 
Python :: serialization in python 
Python :: python plot confidence interval 
Python :: python remove list from nested list 
Python :: python class variable 
Python :: how to make dice roll in python 
Python :: add rectangle to image python 
Python :: python http server 
Python :: padding figures in pyplot 
Python :: divide list into equal parts python 
Python :: boolean python example 
Python :: python button click code 
Python :: np.pad 
Python :: shallow copy deep copy python 
Python :: python virtual env 
Python :: combination in python math 
Python :: fastest way to check odd or even in python 
ADD CONTENT
Topic
Content
Source link
Name
8+4 =