-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
38 lines (30 loc) · 1.03 KB
/
main.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
import os
import openai
import Recording as RC
import VoiceSynthesis as VS
if __name__ == "__main__":
out_file = 'demo.wav'
rec_time = 3 # Recording time
speed = 180 # speeking speed
openai.api_key = "Your API key"
openai.organization = os.getenv("OPENAI_ORGANIZATION")
conversation = []
while(True):
# Recording
RC.record_audio(out_file)
# Voice recognizition
audio_file = open(out_file, "rb")
transcript = openai.Audio.transcribe("whisper-1", audio_file)
user_input = transcript['text']
print(user_input)
conversation.append({"role": "user", "content":user_input})
# ChatGPT
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=conversation
)
output_text = response['choices'][0]['message']['content'];
conversation.append({"role": "assistant", "content": output_text})
print('\n'+output_text)
#Voice synthesis
VS.TextToVoice(output_text, speed)