import cv2
import os
import numpy as np
import speech_recognition as s_r
from translate import Translator
import speech_recognition as s_r
print(s_r.__version__) # just to print the version not required
r = s_r.Recognizer()
my_mic = s_r.Microphone(device_index=1) #my device index is 1, you have to put your device index
with my_mic as source:
print("microphone on...... ")
r.adjust_for_ambient_noise(source) #reduce noise
audio = r.listen(source) #take voice input from the microphone
print(r.recognize_google(audio, language="ar-AR")) #to print voice into text
text=r.recognize_google(audio, language="ar-AR")
translator=Translator(from_lang="Arabic", to_lang="English")
translation = translator.translate(text)
print(translation)
txt= translation
if txt=="Good morning":
os.popen("C:/Program Files (x86)/VideoLAN/VLC/vlc.exe F:/gm.mp4")
elif txt=="Good evening":
os.popen("C:/Program Files (x86)/VideoLAN/VLC/vlc.exe F:/ga.mp4")
elif txt =="Good Night":
os.popen("C:/Program Files (x86)/VideoLAN/VLC/vlc.exe F:/gn.mp4")
elif txt =="Please":
os.popen("C:/Program Files (x86)/VideoLAN/VLC/vlc.exe F:/pls.mp4")
elif txt =="Yes":
os.popen("C:/Program Files (x86)/VideoLAN/VLC/vlc.exe F:/yes.mp4")
elif txt =="No":
os.popen("C:/Program Files (x86)/VideoLAN/VLC/vlc.exe F:/no.mp4")
elif txt=="Thanks":
os.popen("C:/Program Files (x86)/VideoLAN/VLC/vlc.exe F:/ty.mp4")
elif txt=="How are You Doing":
os.popen("C:/Program Files (x86)/VideoLAN/VLC/vlc.exe F:/hru.mp4")
**The code is not going inside the if statements even when it is true. maybe I should define it as str? there are no errors, and I can't make sure that the video file will open **
Aucun commentaire:
Enregistrer un commentaire