-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspeechrecognition_.py
More file actions
107 lines (99 loc) · 3.25 KB
/
Copy pathspeechrecognition_.py
File metadata and controls
107 lines (99 loc) · 3.25 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import speech_recognition as sr
from data_chatbot import *
from fonction_chatbot import *
from fonction_main import *
from script_personelle import *
from random import randint
import os
from arduino import *
import configparser
from time import *
cfg = configparser.ConfigParser()
cfg.read('./config/info.ini')
def say(text):
fichier = open("temp_lecture", "w")
fichier.write(text)
fichier.close()
deconnection_robot()
os.system("py speak.py")
connection_robot()
def phrase_recognition(phrase):
reponse = True
for i in data :
for k in i[0]:
if phrase == k:
text = str(i[1][randint(0, len(i[1])-1)])
print("say -> " + text)
say(text)
reponse = False
try :
i[2][0]()
except:
pass
else :
for j in data_mots_suplementaire_end:
for t in data_mots_suplementaire_start:
if ((phrase == (k + " " + j)) or (phrase == (t + " " + k)) or (phrase == (t + " " + k + " " + j))) and reponse == True:
text = str(i[1][randint(0, len(i[1])-1)])
print("say -> " + text)
say(text)
reponse = False
try :
for fonction in i[2]:
fonction()
except:
pass
if reponse and capital(phrase)==False:
if song(phrase) == False :
say("je ne vous ai pas compris, il me reste encore beaucoup de chose à apprendre")
def song(phrase):
x=""
for i in range(0, 16):
x = x + phrase[i]
if x == "lance la musique" :
nom_musique = ""
for j in range(17, len(phrase)):
nom_musique = nom_musique + phrase[j]
print(nom_musique)
music_ytb(nom_musique)
return(True)
return(False)
def capital(text):
import csv;
f= open("chatbot/capital.csv", encoding="utf8")
capital = csv.reader(f)
capital_pays = []
for row in capital :
capital_pays = capital_pays + [row]
pays_trouver = False
pays = ""
i=0
if (len(text)>22):
while not(pays_trouver) and (len(text)-len(pays))>22:
pays = text[len(text)-1-i] + pays
if pays == (" " + cfg["robot"]["robot_name"]):
pays = ""
i+=1
for liste in capital_pays :
if pays == liste[0]:
print(liste[1])
say("la capitale de " + pays + " est " + liste[1])
pays_trouver = True
return(pays_trouver)
def speak_recognition():
rec_vocal = sr.Recognizer()
mic = sr.Microphone()
rec_vocal.pause_threshold = 0.5
rec_vocal.non_speaking_duration = 0.4
global init_mic
with mic as src:
audio = rec_vocal.listen(src)
try :
text = rec_vocal.recognize_google(audio, language="fr-FR")
print("reconaissance vocal ->" + str(text))
phrase_recognition(str(text))
except :
pass
if __name__ == "__main__":
while True :
speak_recognition()