Probleme de code erreur

Fermé
boby - 2 févr. 2021 à 17:50
yg_be Messages postés 22696 Date d'inscription lundi 9 juin 2008 Statut Contributeur Dernière intervention 17 avril 2024 - 9 févr. 2021 à 20:51
Bonjour,j ai une erreur dans mon code pour la creation d un assistant
le code :


from urllib.request import urlopen
from googletrans import Translator
from random import choice
import speech_recognition as sr
import pyttsx3
import subprocess
import wolframalpha
import webbrowser
import wikipedia

def assistant_voix(sortie):
if sortie != None:
voix = pyttsx3.init()
print("A.I : " + sortie)
voix.say(sortie)
voix.runAndWait()


def internet():
try:
urlopen('https://www.google.com', timeout=1)
print("Connecté")
return True
except:
print("Déconnecté")
return False


def reconnaissance():
r = sr.Recognizer()
r.energy_threshold = 4000
pas_compris = "Désolé, je n'ai pas compris ."
with sr.Microphone() as source:
r.adjust_for_ambient_noise(source)
r.pause_threshold = 0.7
print(".... ")
audio = r.listen(source)
if internet():
try:
vocal = r.recognize_google(audio, language = 'fr-FR')
print(vocal)
return vocal
except sr.UnknownValueError:
assistant_voix(pas_compris)
else:
try:
vocal = r.recognize_sphinx(audio, language = 'fr-fr')
print(vocal)
return vocal
except sr.UnknownValueError:
assistant_voix(pas_compris)

def application(entree):
if entree != None:
dico_apps = {
"visual studio code" = ["visual studio code","studio code"]
"visual studio 2019" = ["visual studio","studio 2019"]
"invite de commande" = ["terminal de commande","invite de commande","terminal"]
"Tom Clancy's Raimbow six siege" = ["r6","raimbow six","tom clancy's","raimbox six siege"]
"minecraft" = ["minecraft"]
"google" = ["google"]
"steam" = ["steam"]
"assetto corsa" = ["assetto","corsa","assetto corsa"]
"wordpad" = ["wordpad"]
"discord" = ["discord"]
"spotify" = ["spotify","musique"]
"photoshop" = ["photoshop","ps"]
"among us" = ["among us"]
"windev " = ["windev"]
"dirt rally" = ["dirt rally","rally","dirt"]
"fusion 360" = ["fusion","fusion 360","autodesk"]
"3ds max" = ["3ds"]
"solidworks" = ["solid works"]
"excel" = ["excel"]
"word" = ["word"]
"panneau de configuration" = ["configuration","panneau de configuration"]
}
fini = False
while not fini:
for x in dico_apps["visual studio code"]:
if x in entree.lower():
assistant_voix("Ouverture de visual studio code")
subprocess.Popen(C:\Users\Utilisateur\AppData\Local\Programs\Microsoft VS Code\Code.exe)
fini = True
for x in dico_apps["visual studio 2019"]:
if x in entree.lower():
assistant_voix("Ouverture de visual studio 2019")
subprocess.Popen(C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\devenv.exe)
fini = True
for x in dico_apps["invite de commande"]:
if x in entree.lower():
assistant_voix("Ouverture de l'invite de commande")
subprocess.Popen(%windir%\system32\cmd.exe)
fini = Truefor x in dico_apps["Tom Clancy's Raimbow six siege"]:
if x in entree.lower():
assistant_voix("Ouverture de raimbow six siege")
subprocess.Popen(C:\Users\Utilisateur\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Tom Clancy's Rainbow Six Siege)
fini = True
for x in dico_apps["minecraft"]:
if x in entree.lower():
assistant_voix("Ouverture de minecraft")
subprocess.Popen(C:\Program Files (x86)\Minecraft Launcher\MinecraftLauncher.exe)
fini = True
for x in dico_apps["google"]:
if x in entree.lower():
assistant_voix("Ouverture de google")
subprocess.Popen(C:\Program Files (x86)\Google\Chrome\Application\chrome.exe)
fini = True
for x in dico_apps["steam"]:
if x in entree.lower():
assistant_voix("Ouverture de steam")
subprocess.Popen(C:\Program Files (x86)\Steam\Steam.exe)
fini = True
for x in dico_apps["assetto corsa"]:
if x in entree.lower():
assistant_voix("Ouverture de assetto corsa")
subprocess.Popen(C:\Users\Utilisateur\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Steam\Assetto Corsa)
fini = True
for x in dico_apps["wordpad"]:
if x in entree.lower():
assistant_voix("Ouverture de wordpad")
subprocess.Popen(%ProgramFiles%\Windows NT\Accessories\wordpad.exe)
fini = True
for x in dico_apps["discord"]:
if x in entree.lower():
assistant_voix("Ouverture de discord")
subprocess.Popen(C:\Users\Utilisateur\AppData\Local\Discord\Update.exe --processStart Discord.exe)
fini = True
for x in dico_apps["spotify"]:
if x in entree.lower():
assistant_voix("Ouverture de spotify")
subprocess.Popen(C:\Users\Utilisateur\AppData\Roaming\Spotify\Spotify.exe)
fini = True
for x in dico_apps["photoshop"]:
if x in entree.lower():
assistant_voix("Ouverture de photoshop")
subprocess.Popen(C:\Users\Utilisateur\Desktop\Adobe Photoshop 2020\Photoshop.exe)
fini = True
for x in dico_apps["among us"]:
if x in entree.lower():
assistant_voix("Ouverture d'among us")
subprocess.Popen(C:\Program Files\BlueStacks\HD-RunApp.exe" -json "{\"app_icon_url\":\"\",\"app_name\":\"Among Us\",\"app_url\":\"\",\"app_pkg\":\"com.innersloth.spacemafia\"})
fini = True
for x in dico_apps["windev"]:
if x in entree.lower():
assistant_voix("Ouverture de windev")
subprocess.Popen(C:\Program Files (x86)\PC SOFT\WINDEV 25 Express\Programmes\WDExpress.exe)
fini = True
for x in dico_apps["dirt rally"]:
if x in entree.lower():
assistant_voix("Ouverture de dirt rally")
subprocess.Popen(C:\Users\Utilisateur\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Steam\DiRT Rally)
fini = True
for x in dico_apps["fusion 360"]:
if x in entree.lower():
assistant_voix("Ouverture de fusion 360")
subprocess.Popen(C:\Users\Utilisateur\AppData\Local\Autodesk\webdeploy\production\6a0c9611291d45bb9226980209917c3d\FusionLauncher.exe)
fini = True
for x in dico_apps["3ds max"]:
if x in entree.lower():
assistant_voix("Ouverture de 3ds max")
subprocess.Popen(C:\Program Files\Autodesk\3ds Max 2016\3dsmax.exe)
fini = True
for x in dico_apps["solidworks"]:
if x in entree.lower():
assistant_voix("Ouverture de solidworks")
subprocess.Popen(C:\Program Files\Common Files\SOLIDWORKS Shared\2020\sldrx\)
fini = True
for x in dico_apps["excel"]:
if x in entree.lower():
assistant_voix("Ouverture de excel")
subprocess.Popen(C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Microsoft Office\Microsoft Office Excel 2007)
fini = True
for x in dico_apps["word"]:
if x in entree.lower():
assistant_voix("Ouverture de word")
subprocess.Popen(C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Microsoft Office\Microsoft Office Word 2007)
for x in dico_apps["panneau de configuration"]:
if x in entree.lower():
assistant_voix("Ouverture du panneau de configuration")
subprocess.Popen(C:\Users\Utilisateur\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\System Tools\Panneau de configuration)
fini = True

def calcul(entree):
if entree != None:
traducteur = Translator()
traduction = traducteur.translate(text = entree, dest = "en").text
app_id = "L5H3JP-ERXK3EVKGW"
client = wolframalpha.Client(app_id)
res = client.query(traduction)
try:
reponse = next(res.results).text
traduction_reponse = traducteur.translate(text = reponse, dest = "fr").text
assistant_voix("le résultat est %d" %(traduction_reponse))
except:
assistant_voix("Il y'a eu une erreur, désolé")

def sur_le_net(entree):
if entree != None:
if "youtube" in entree.lower():
indx = entree.lower().split().index("youtube")
recherche = entree.lower().split()[indx + 1:]
if len(recherche) != 0:
assistant_voix("recherche sur YouTube .")
webbrowser.open("http://www.youtube.com/results?search_query=" + "+".join(recherche), new = 2)
elif "wikipédia" in entree.lower():
wikipedia.set_lang("fr")
try:
recherche = entree.lower().replace("cherche sur wikipédia","")
if len(recherche) != 0:
resultat = wikipedia.summary(recherche, sentences = 1)
assistant_voix("recherche sur Wikipédia .")
assistant_voix(resultat)
except:
assistant_voix("Désolé, aucune page trouvée .")
else:
if "google" in entree.lower():
indx = entree.lower().split().index("google")
recherche = entree.lower().split()[indx + 1:]
if len(recherche) != 0:
assistant_voix("recherche sur Google .")
webbrowser.open("https://www.google.com/search?q=" + "+".join(recherche), new = 2)
elif "cherche" in entree.lower() or "recherche" in entree.lower():
indx = entree.lower().split().index("cherche")
recherche = entree.lower().split()[indx + 1:]
if len(recherche) != 0:
assistant_voix("recherche par défaut .")
webbrowser.open("https://www.google.com/search?q=" + "+".join(recherche), new = 2)
elif "recherche" in entree.lower():
indx = entree.lower().split().index("recherche")
recherche = entree.lower().split()[indx + 1:]
if len(recherche) != 0:
assistant_voix("recherche sur Google .")
webbrowser.open("http://www.google.com/search?q="+"+".join(recherche), new = 2)

def main():
assistant_voix("Bonjour,comment va tu aujourd'hui")
fermer = ["arrête-toi","tais-toi","chut","stop","eteind toi"]
quisuisje = ["qui est tu ?","comment tu t'appelles",]
aquoitusers = ["a quoi tu sers","tu sers a quoi","quel sont tes capacité?"]
doutuviens = ["d'ou viens tu ?","d'ou tu viens?",]
parents = ["qui sont tes parents?","tu connais tes parents?","qui est ton pere?","qui est ta mere"]
cava = ["bien et toi","tu vas bien ?","comment tu te sens","ca va ?","comment tu vas","tu vas","vas tu"]
quefaistu = ["tu fais quoi?","que fais tu?","qu es se que tu fais?",]
ouvrir = ["ouvre","ouvrir"]
cherche = ["cherche sur youtube","cherche sur google","cherche sur wikipédia","cherche","trouve","regarde sur","raconte moi"]
calculs = ["calcule la somme de","calcule la différence de"," calcule le produit de","calcule le quotient de","calcule"]
actif = True
while actif:
if (entree := reconnaissance()) is not None:
for x in range(len(fermer)):
if fermer[x] in entree.lower():
assistant_voix("A bientôt .","aurevoir","a une prochaine fois")
actif = False
for x in range(len(quisuisje)):
if quisuisje[x] in entree.lower():
assistant_voix("je suis boby ton assistant","ton assistant, boby","appelle moi boby")
actif = False
for x in range(len(aquoitusers)):
if aquoitusers[x] in entree.lower():
assistant_voix("je suis ton assistant donc je peux faire des recherches , ouvrir des applications ect...","tout se que tu me demandes","j ai plein de capacité exploitable")
actif = False
for x in range(len(doutuviens)):
if doutuviens[x] in entree.lower():
assistant_voix("j'en est aucune idée","j'espere savoir un jour","je cherche de temps en temps")
actif = False
for x in range(len(parents)):
if parents[x] in entree.lower():
assistant_voix("techniquement mon pere est noa et je n'ai pas de mere")
actif = False
for x in range(len(cava)):
if cava[x] in entree.lower():
assistant_voix("tres bien je te remercie","tres bien comme toujours","parfait merci","je serai encore plus heureux si je pouvais te rendre service","j irai mieux si je pouvais t aider")
actif = False
for x in range(len(quefaistu)):
if quefaistu[x] in entree.lower():
assistant_voix("j attend vos demande","je me perfectionne pour me rendre plus utile","je vide vos compte bancaire , , , non je deconne")
actif = False
for x in range(len(ouvrir)):
if ouvrir[x] in entree.lower():
application(entree)
break
for x in range(len(cherche)):
if cherche[x] in entree.lower():
sur_le_net(entree)
break
for x in range(len(calculs)):
if calculs[x] in entree.lower():
calcul(entree)
break

if __name__ == '__main__':
main()






voici le message qu il me met quand j essaie de le lancer : File "C:\xampp\htdocs\paypaltest\code.py", line 56
"visual studio code" = ["visual studio code","studio code"]
^
SyntaxError: invalid syntax
MAIS je n arrive pas a resoudre le probleme pouvez vous m aidez svp?
A voir également:

2 réponses

Phil_1857 Messages postés 1883 Date d'inscription lundi 23 mars 2020 Statut Membre Dernière intervention 28 février 2024 178
2 févr. 2021 à 17:58
Bonjour,

dico_apps, c'est un dictionnaire au sens de Python ?

Dans ce cas, ce n'est pas comme ça que ça s'initialise

voir définition d'un dictionnaire en Python sur Internet ...

Ceci étant posé, l'indentation étant importante en Python, tu aurais du copier/coller ici ton code

avec les balises de code, mode d'emploi:

https://codes-sources.commentcamarche.net/faq/11288-les-balises-de-code

Visuellement, ça doit ressembler à ceci (avec la coloration syntaxique) :

def test():
    print('test')

test()
0
Phil_1857 Messages postés 1883 Date d'inscription lundi 23 mars 2020 Statut Membre Dernière intervention 28 février 2024 178
2 févr. 2021 à 18:36
Google est ton ami !

"dictionnaires en Python" ...
0
merci
0
yg_be Messages postés 22696 Date d'inscription lundi 9 juin 2008 Statut Contributeur Dernière intervention 17 avril 2024 1 471 > boby
9 févr. 2021 à 20:51
peux-tu alors marquer la discussion comme résolue?
0