-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.py
57 lines (47 loc) · 1.44 KB
/
utils.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
51
52
53
54
55
56
57
from openai import OpenAI
import time
from pathlib import Path
client = OpenAI()
def get_transcript(audiopath):
audio_file= open(audiopath, "rb")
transcript = client.audio.transcriptions.create(
model="whisper-1",
file=audio_file
)
return transcript.text
def get_assistant_reply(query):
threadId = "<Your Thread ID>"
assistantId = "<Your Assistant ID>"
message = client.beta.threads.messages.create(
thread_id=threadId,
role="user",
content=query
)
run = client.beta.threads.runs.create(
thread_id=threadId,
assistant_id=assistantId,
instructions="Please provide very short and to the point frank responses.."
)
response = "Couldn't get response. something went wrong."
while True:
run = client.beta.threads.runs.retrieve(
thread_id=threadId,
run_id=run.id
)
time.sleep(1)
if run.status == 'completed':
messages_ = client.beta.threads.messages.list(
thread_id=threadId,
)
response = messages_.data[0].content[0].text.value
break
return response
def get_text_to_audio(text):
speech_file_path = Path(__file__).parent / "speech.mp3"
response = client.audio.speech.create(
model="tts-1",
voice="nova",
input=text
)
response.stream_to_file(speech_file_path)
return "speech.mp3"