diff --git a/audio/audio.py b/audio/audio.py index c990ecd..b3a316f 100644 --- a/audio/audio.py +++ b/audio/audio.py @@ -98,5 +98,33 @@ class Audio: self.playbackStream.stop_stream() self.playbackStream.close() + def playFile(self, fileName: str): + # open the file for reading. + wf = wave.open(fileName, "rb") + + # create an audio object + p = pyaudio.PyAudio() + + # open stream based on the wave object which has been input. + stream = p.open( + format=p.get_format_from_width(wf.getsampwidth()), + channels=wf.getnchannels(), + rate=wf.getframerate(), + output=True, + output_device_index=RESPEAKER_INDEX, + ) + + # read data (based on the chunk size) + data = wf.readframes(CHUNK) + # play stream (looping from beginning of file to the end) + while data: + # writing to the stream is what *actually* plays the sound. + stream.write(data) + data = wf.readframes(CHUNK) + + # cleanup stuff. + stream.close() + p.terminate() + def terminate(self): self.pyaudio.terminate() diff --git a/tts/app.py b/tts/app.py new file mode 100644 index 0000000..3c6bb15 --- /dev/null +++ b/tts/app.py @@ -0,0 +1,22 @@ +# this program will record audio while the button is pressed +# and then will transcribe it by hitting our api + +# NOTE: run export PYTHONPATH=$PYTHONPATH:$(pwd) to run this file from the root directory of the project +# so that all different modules can be used + +import audio.audio as audio +import requests + +API_URL = "http://192.168.50.159:5001/tts" + +audioInstance = audio.Audio() + +response = requests.post(API_URL, data={'text': 'hello world'}) +print(response) + +# get the file data from the response +# write the file data to a file +# save the file + +# play the file +audioInstance.playFile('audio.wav') diff --git a/tts/requirements.txt b/tts/requirements.txt new file mode 100644 index 0000000..b774f77 --- /dev/null +++ b/tts/requirements.txt @@ -0,0 +1,6 @@ +certifi==2022.12.7 +charset-normalizer==3.1.0 +idna==3.4 +PyAudio==0.2.13 +requests==2.29.0 +urllib3==1.26.15 diff --git a/voice-server/.DS_Store b/voice-server/.DS_Store index 5008ddf..8f27ecc 100644 Binary files a/voice-server/.DS_Store and b/voice-server/.DS_Store differ