我正在寻找一个循环系统(受Marc Rebillet的启发,看看他),并且正在努力让 2 种声音自己播放。
我已经开始使用 sounddevice,因为它是我发现的第一个音频模块,但我不确定是否有其他更好的音频模块。
import time
def record(duration): # records a few seconds of audio
print('recording in:')
print('3')
time.sleep(1)
print('2')
time.sleep(1)
print('1')
time.sleep(1)
print('recording')
record = sd.rec(int(duration * fs), samplerate=48000, channels=2)
sd.wait()
print('done\n\n')
return record
duration = 3.5 # seconds
recordOne = record(duration)
recordTwo = record(duration)
while True: # repeats both pieces of audio
sd.play(recordOne, fs)
sd.play(recordTwo, fs)
sd.wait()
这段代码最终只播放了 recordTwo,并没有将它们叠加在一起。同样,我希望能够同时播放多个声音。感谢您的任何帮助!