pyaudio playing noise at this point
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1 +1,2 @@
|
|||||||
.env
|
.env
|
||||||
|
*.wav
|
||||||
@@ -40,22 +40,46 @@ def stream_audio_to_virtual_mic(text, voice="fable", device_index=None):
|
|||||||
p = pyaudio.PyAudio()
|
p = pyaudio.PyAudio()
|
||||||
if device_index is None:
|
if device_index is None:
|
||||||
device_index = int(input("Enter the device index: "))
|
device_index = int(input("Enter the device index: "))
|
||||||
|
|
||||||
stream = p.open(format=pyaudio.paInt16,
|
stream = p.open(format=pyaudio.paInt16,
|
||||||
channels=1,
|
channels=1,
|
||||||
rate=22050, # Adjust the rate to match the audio format
|
rate=22050, # Adjust the rate to match the audio format
|
||||||
output=True,
|
output=True,
|
||||||
output_device_index=device_index)
|
output_device_index=device_index)
|
||||||
|
|
||||||
# Stream audio chunks to virtual microphone
|
# Stream audio chunks to virtual microphone
|
||||||
try:
|
try:
|
||||||
for chunk in response.iter_chunks():
|
for chunk in response.iter_lines():
|
||||||
stream.write(chunk)
|
stream.write(chunk)
|
||||||
|
|
||||||
|
##write to text file for testing
|
||||||
|
with open("test_output.wav", "wb") as f:
|
||||||
|
f.write(response.content)
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
# Ensure resources are cleaned up
|
# Ensure resources are cleaned up
|
||||||
stream.stop_stream()
|
stream.stop_stream()
|
||||||
stream.close()
|
stream.close()
|
||||||
p.terminate()
|
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__":
|
if __name__ == "__main__":
|
||||||
import sys
|
import sys
|
||||||
if len(sys.argv) < 2:
|
if len(sys.argv) < 2:
|
||||||
|
|||||||
Reference in New Issue
Block a user