getting request and writing to file working
This commit is contained in:
+17
-6
@@ -11,12 +11,23 @@ API_URL = "http://192.168.50.159:5001/tts"
|
|||||||
|
|
||||||
audioInstance = audio.Audio()
|
audioInstance = audio.Audio()
|
||||||
|
|
||||||
response = requests.post(API_URL, data={'text': 'hello world'})
|
# send request with json
|
||||||
print(response)
|
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
|
# get the file data from the response and write to temp local file
|
||||||
# write the file data to a file
|
fileName = "output.wav"
|
||||||
# save the file
|
# todo: move this writing process to audio.py
|
||||||
|
with open(fileName, 'wb') as f:
|
||||||
|
f.write(response.content)
|
||||||
|
|
||||||
|
f.close()
|
||||||
|
|
||||||
# play the file
|
# play the file
|
||||||
audioInstance.playFile('audio.wav')
|
audioInstance.playFile(fileName)
|
||||||
|
|||||||
Binary file not shown.
+4
-4
@@ -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
|
from dotenv import load_dotenv
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
|
|
||||||
from flask import Flask, request, abort, send_file
|
|
||||||
from tempfile import NamedTemporaryFile
|
|
||||||
import tts
|
|
||||||
import whisper
|
|
||||||
|
|
||||||
# Load the Whisper model:
|
# Load the Whisper model:
|
||||||
model = whisper.load_model("base")
|
model = whisper.load_model("base")
|
||||||
|
|||||||
Binary file not shown.
@@ -3,6 +3,8 @@ import google.cloud.texttospeech as tts
|
|||||||
OUTPUT_FILE = "output.wav"
|
OUTPUT_FILE = "output.wav"
|
||||||
|
|
||||||
# todo: make sure to make the file name unique and delete it after sending
|
# todo: make sure to make the file name unique and delete it after sending
|
||||||
|
|
||||||
|
|
||||||
def text_to_wav(voice_name: str, text: str):
|
def text_to_wav(voice_name: str, text: str):
|
||||||
language_code = "-".join(voice_name.split("-")[:2])
|
language_code = "-".join(voice_name.split("-")[:2])
|
||||||
text_input = tts.SynthesisInput(text=text)
|
text_input = tts.SynthesisInput(text=text)
|
||||||
|
|||||||
Reference in New Issue
Block a user