Answer the question
In order to leave comments, you need to log in
How to play stereo sound without saving to file (Python)?
Hello.
There is a program that creates stereo sound and saves it to a file
import wave
import numpy as np
time = 25
di = 44100
wavef = wave.open('audio.wav','w')
wavef.setnchannels(2)
wavef.setsampwidth(2)
wavef.setframerate(44100)
t = np.linspace(0, 25, di*25, endpoint = False)
l = 10000*np.sin(2*np.pi*t*500)
r = 10000*np.sin(2*np.pi*t*2000)
for i in range(di*time):
wavef.writeframesraw( struct.pack('<hh', int(l[i]), int(r[i]) ) )
Answer the question
In order to leave comments, you need to log in
It seems to me that you can use this option to not use the file
memfile = io.BytesIO()
wavef = wave.open(memfile, 'wb')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question