diff --git a/.DS_Store b/.DS_Store index fd7a49c..22fbe1a 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/tts/app.py b/tts/app.py index 3c6bb15..ae0bf1b 100644 --- a/tts/app.py +++ b/tts/app.py @@ -11,12 +11,23 @@ API_URL = "http://192.168.50.159:5001/tts" audioInstance = audio.Audio() -response = requests.post(API_URL, data={'text': 'hello world'}) -print(response) +# send request with json +headers = { + "Content-type": "application/json", +} +response = requests.post( + API_URL, + headers=headers, + json={"text": "hello world. the weather today is sunny."} +) -# get the file data from the response -# write the file data to a file -# save the file +# get the file data from the response and write to temp local file +fileName = "output.wav" +# todo: move this writing process to audio.py +with open(fileName, 'wb') as f: + f.write(response.content) + + f.close() # play the file -audioInstance.playFile('audio.wav') +audioInstance.playFile(fileName) diff --git a/tts/output.wav b/tts/output.wav new file mode 100644 index 0000000..dec4563 Binary files /dev/null and b/tts/output.wav differ diff --git a/voice-server/app.py b/voice-server/app.py index c9853fd..78feefb 100644 --- a/voice-server/app.py +++ b/voice-server/app.py @@ -1,10 +1,10 @@ +import whisper +import tts +from tempfile import NamedTemporaryFile +from flask import Flask, request, abort, send_file from dotenv import load_dotenv load_dotenv() -from flask import Flask, request, abort, send_file -from tempfile import NamedTemporaryFile -import tts -import whisper # Load the Whisper model: model = whisper.load_model("base") @@ -54,7 +54,7 @@ def text_to_speech(): # get the text from the request json content = request.get_json() text = content['text'] - + if not text: abort(400, "Please provide text to convert to speech!") diff --git a/voice-server/output.wav b/voice-server/output.wav new file mode 100644 index 0000000..dec4563 Binary files /dev/null and b/voice-server/output.wav differ diff --git a/voice-server/tts.py b/voice-server/tts.py index 1f9cedf..aec853e 100644 --- a/voice-server/tts.py +++ b/voice-server/tts.py @@ -3,6 +3,8 @@ import google.cloud.texttospeech as tts OUTPUT_FILE = "output.wav" # todo: make sure to make the file name unique and delete it after sending + + def text_to_wav(voice_name: str, text: str): language_code = "-".join(voice_name.split("-")[:2]) text_input = tts.SynthesisInput(text=text)