-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsample.py
36 lines (31 loc) · 1.01 KB
/
sample.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
import os
import time
# from docx import Document
from dotenv import load_dotenv
from openai import OpenAI
from app.audio import SpeechToTextConverter, TextToSpeechConverter
from app.openai import OpenAiQuery
load_dotenv()
client = OpenAI(api_key=os.environ.get("OPENAI_API_KEY"))
tts_converter = TextToSpeechConverter(client)
stt_converter = SpeechToTextConverter(client)
query_engine = OpenAiQuery(client)
tts_converter.default_renderer = "chatgpt"
# stt_converter.default_renderer = "gtts"
enable_voice = True
n = 10
for i in range(n):
question = ""
if enable_voice:
question = stt_converter.convert()
else:
question = "Can you give me ten sample sentences?"
if question:
print("Question: ", question)
for sentence in query_engine.get_openai_responses_in_sentences(
question=question
):
print("Response sentence: ", sentence)
tts_converter.convert(text=sentence)
while not tts_converter.playback_complete:
time.sleep(1)