My use case is to convert text to speech using Azure and then play it into a virtual microphone.
I tried both steps manually on a Jupiter notebook.
The problem is, the output .wav file of Azure cannot be played directly on the python
"error: No file 'file.wav' found in working directory". When I restart the python kernal, audio can be played.
audio_config = speechsdk.audio.AudioOutputConfig(filename="file.wav")
...
speech_synthesizer = speechsdk.SpeechSynthesizer(speech_config=speech_config, audio_config=audio_config)
speech_synthesis_result = speech_synthesizer.speak_text_async(text).get()
mixer.init(devicename = 'Line 1 (Virtual Audio Cable)')
mixer.music.load("file.wav")
mixer.music.play()
I tried to configure the audio output device of azure SDK. this method worked for output devices. but when I add an ID of the virtual microphone, it won't play any sound.
audio_config = speechsdk.audio.AudioOutputConfig(use_default_speaker=False,device_name="{0.0.0.00000000}.{9D30BDBF-1418-4AFC-A709-CD4C431833E2}")
I found a solution by changing the output a stream, saving to a file and then play it through pygame as follows,
speech_synthesizer = speechsdk.SpeechSynthesizer(speech_config=speech_config, audio_config=None)
speech_synthesis_result = speech_synthesizer.speak_text_async(text).get()
stream = speechsdk.AudioDataStream(speech_synthesis_result)
stream.save_to_wav_file("file.wav")
mixer.init(devicename = 'Line 1 (Virtual Audio Cable)')
mixer.music.load("file.wav")
mixer.music.play()
Also much appreciated if there is any other method that doesn't need any intermediate audio file.