-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvoice.py
More file actions
47 lines (39 loc) · 1.13 KB
/
Copy pathvoice.py
File metadata and controls
47 lines (39 loc) · 1.13 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
import openai
import pyttsx3
import speech_recognition as sr
# Clé d'API
openai.api_key = "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"
# Initialiser le recognizer
r = sr.Recognizer()
# Initialiser le moteur de synthèse vocale
engine = pyttsx3.init()
while True:
# Ecouter pour la commande vocale
with sr.Microphone() as source:
print("Ecoute...")
audio = r.listen(source)
# Transcrire la commande vocale
try:
prompt = r.recognize_google(audio, language="fr-FR")
print("Tu as dit: " + prompt)
if prompt == "exit":
break
except sr.UnknownValueError:
print("Je n'ai pas compris")
continue
except sr.RequestError as e:
print("Erreur de service; {0}".format(e))
continue
# Envoyer une requête à l'API
response = openai.Completion.create(
engine="text-davinci-003",
prompt=prompt,
max_tokens=2048,
n=1,
stop=None,
temperature=0.5,
)
# Afficher la réponse
print(response["choices"][0]["text"])
engine.say(response["choices"][0]["text"])
engine.runAndWait()