From 4ccebf0cdc75285d865c2b97b0ee3901d7e596d8 Mon Sep 17 00:00:00 2001 From: Andrew Ward Date: Wed, 1 May 2024 12:45:53 +0100 Subject: [PATCH] pyaudio playing noise at this point --- .gitignore | 3 ++- text-to-mic.py | 28 ++++++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 2eea525..26e8a09 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -.env \ No newline at end of file +.env +*.wav \ No newline at end of file diff --git a/text-to-mic.py b/text-to-mic.py index c0d7872..58e1d32 100644 --- a/text-to-mic.py +++ b/text-to-mic.py @@ -40,21 +40,45 @@ def stream_audio_to_virtual_mic(text, voice="fable", device_index=None): p = pyaudio.PyAudio() if device_index is None: device_index = int(input("Enter the device index: ")) + stream = p.open(format=pyaudio.paInt16, channels=1, rate=22050, # Adjust the rate to match the audio format output=True, output_device_index=device_index) - # Stream audio chunks to virtual microphone + # Stream audio chunks to virtual microphone try: - for chunk in response.iter_chunks(): + for chunk in response.iter_lines(): stream.write(chunk) + + ##write to text file for testing + with open("test_output.wav", "wb") as f: + f.write(response.content) + finally: # Ensure resources are cleaned up stream.stop_stream() stream.close() p.terminate() + + """ + # Stream audio chunks to virtual microphone + try: + # Ensure you are handling the response's binary content correctly + # Adjust the method to access binary data as per the latest library version or response object + audio_data = response.content # This might need adjustment based on actual response object methods + stream.write(audio_data) + + ##write to text file for testing + with open("test_output.wav", "wb") as f: + f.write(response.content) + + finally: + stream.stop_stream() + stream.close() + p.terminate() + """ if __name__ == "__main__": import sys