In my program, I am using a function to play audio from a file:
import asyncio
import soundfile
import sounddevice
audio_device = 'Audio Device'
async def play_audio(file):
data,fs = soundfile.read(file)
sounddevice.play(data,fs,device=audio_device)
#sounddevice.wait()
async def main():
while True:
user_input = input('>')
await play_audio(user_input)
asyncio.run(main())
The problem is that when the file is playing and I give another user_input, the audio immediately stops playing and plays the requested file. I would like my function to finish playing the first audio file before playing the next.
I have tried adding the sounddevice.wait() line but this prevents me from adding user_inputs while the audio is being played. In the actual program I am using text to speech to generate audio files and want the program to generate the next input while playing the audio to save time, but I want the audio to finish playing before playing the next audio file.
feed flame is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.