I'm using the sounddevice library for Python. So far I was able to do some basic stuff with audio files through this library, like playing back a WAV format file using this code from one of the tutorials:
#!/usr/bin/env python3
import sounddevice as sd
import soundfile as sf
try:
data, fs = sf.read('[path to audio file]', dtype='float32')
sd.play(data, fs, device=None)
status = sd.wait()
except KeyboardInterrupt:
print("Keyboard interrupt")
except Exception as e:
print("Internal exception")
However, I need to redirect that audio output to the system's microphone input instead of the speakers, and I'm not sure how to do that with this library since there isn't a lot of clear documentation on this. Is there a way to do this with sounddevice? I would like to avoid directly interacting with the OS sound drivers, since ideally this should be cross-platform.
Thanks!
Edit: It seems like it's not possible to make this fully cross-platform, so ideally I would like to be able to use this with Windows and the WSAPI.
question from:
https://stackoverflow.com/questions/65895838/redirect-audio-output-to-input-stream-python-sounddevice 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…