-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathass.py
More file actions
74 lines (47 loc) · 1.44 KB
/
ass.py
File metadata and controls
74 lines (47 loc) · 1.44 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import openai
import pyttsx3
import speech_recognition as sr
from gtts import gTTS
import datetime
openai.api_key = "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"
Now = datetime.datetime.now()
Time = Now.strftime("%H_%M_%S")
v_engine = pyttsx3.init()
v_engine.setProperty('volume', 1.0)
v_engine.setProperty('rate', 120)
# Set the voice to use
voices = v_engine.getProperty('voices')
v_engine.setProperty('voice', voices[1].id)
v_engine.say("Hello, I am davinci")
def chatbot(prompt):
completions = openai.Completion.create(
engine="text-davinci-003",
prompt=prompt,
max_tokens=1024,
n=1,
stop=None,
temperature=0.5,
)
message = completions.choices[0].text #type: ignore
return message
def speak(text):
tts = gTTS(text=text, lang='en')
filename = f"{Time}"
tts.save(f'')
r = sr.Recognizer()
while True:
with sr.Microphone() as source:
print("Listening....\n")
audio = r.listen(source)
try:
user_input = r.recognize_google(audio)
print("You said:\n", user_input)
if user_input == "exit":
break
response = chatbot(user_input)
print("Chatbot:\n", response)
speak(response)
except sr.UnknownValueError:
print("Could not understand audio")
except sr.RequestError as e:
print("Error requesting results from Google Speech Recognition service; {0}".format(e))