forked from adds-rag/TouchlessBrowse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtext_to_speech.py
50 lines (37 loc) · 1.36 KB
/
text_to_speech.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# from pathlib import Path
from openai import *
import record_audio_convert_to_text
import key
from playsound import playsound
"""
MAIN FUNCTION
Function to take a string of text and convert it to speech
Params:
text - a string of the provided text
speech_file_path - a string of the file path to save the audio file to
Returns:
Nothing
"""
def text_to_speech(text, speech_file_path="audio_files/GPTSpeech.mp3"):
client = OpenAI(api_key=key.OpenAIKey())
response = client.audio.speech.create(
model="tts-1",
voice="alloy",
input=text,
)
response.stream_to_file("C:/Users/adhit/OneDrive/Files/Documents/QHacks 2023/github/VoiceBrowse/audio_files/GPTSpeech.mp3")
playsound("C:/Users/adhit/OneDrive/Files/Documents/QHacks 2023/github/VoiceBrowse/audio_files/GPTSpeech.mp3")
def text_to_speech_TEST():
client = OpenAI(api_key=key.OpenAIKey())
text = record_audio_convert_to_text.record_whisper_audio_transcript()
# CHANGE THE CALL BELOW TO WHATEVER IS BEING RETURNED
# text = "sample text"
speech_file_path = "VoiceBrowse/audio_files/GPTSpeech.mp3"
response = client.audio.speech.create(
model="tts-1",
voice="alloy",
input=text,
)
response.stream_to_file(speech_file_path)
# text_to_speech()
# text_to_speech("Hi there")