I am trying to run two methods at the same time in Python. One of them plays a sound, and the other records it. Both methods work fine, but I could not figure out how to run them simultaneously, as well as multiprocessing and threads. While I'm pretty sure this cannot be resolved using streaming.
def listen_to_audio() def play_audio()
Any ideas? (They should not end at the same time, but both should begin in a second.)
This is the code, sorry for not sending it at the beginning:
import pyaudio import wave import sys import time from math import * from getopt import * import threading def make_sin(f0=1000.,ampl=30000,rate=22050,length=5.): a = 2. * pi * f0/rate n = int(rate * length) wav='' for i in range(0, n): f = int(ampl*sin(a*i)) wav += chr(f & 0xFF) + chr((f & 0xFF00) >> 8) return wav def play_audio(forHowLong): data = make_sin(f0=1000.,ampl=30000,rate=22050,length=5.) p = pyaudio.PyAudio()
source share