-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtext.py
More file actions
53 lines (37 loc) · 1.23 KB
/
text.py
File metadata and controls
53 lines (37 loc) · 1.23 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
import os
import time
import pyaudio
import speech_recognition as sr
import playsound
from gtts import gTTS
import openai
api_key = "Change this"
lang ='en'
openai.api_key = api_key
guy = ""
while True:
def get_adio():
r = sr.Recognizer()
with sr.Microphone(device_index=1) as source:
audio = r.listen(source)
said = ""
try:
said = r.recognize_google(audio)
print(said)
global guy
guy = said
if "Friday" in said:
words = said.split()
new_string = ' '.join(words[1:])
print(new_string)
completion = openai.ChatCompletion.create(model="gpt-3.5-turbo", messages=[{"role": "user", "content":said}])
text = completion.choices[0].message.content
speech = gTTS(text = text, lang=lang, slow=False, tld="com.au")
speech.save("welcome1.mp3")
playsound.playsound("welcome1.mp3")
except Exception:
print("Exception")
return said
if "stop" in guy:
break
get_adio()