J'ai utilisé speech_recognition.AudioFile
dans Python 3.6, mais cette erreur a été indiquée:
#!/usr/bin/env python3 import speech_recognition as sr # obtain path to "english.wav" in the same folder as this script from os import path AUDIO_FILE = path.join(path.dirname(path.realpath(__file__)), "english.wav") # AUDIO_FILE = path.join(path.dirname(path.realpath(__file__)), "french.aiff") # AUDIO_FILE = path.join(path.dirname(path.realpath(__file__)), "chinese.flac") # use the audio file as the audio source r = sr.Recognizer() with sr.AudioFile(AUDIO_FILE) as source: audio = r.record(source) # read the entire audio file
Voici mon code:
AttributeError: module 'speech_recognition' has no attribute 'AudioFile'
3 Réponses :
Pouvez-vous passer à une version plus récente de SpeechRecognition? Votre code fonctionne correctement avec la dernière version, mais la version 3.1.3 ne semble pas encore avoir cette fonctionnalité et déclenche l'erreur pour moi également.
Le nom de fichier de votre script est-il également appelé speech_recognition.py? Quelqu'un a eu ce problème: Reconnaissance vocale: AttributeError: le module 'speech_recognition' n'a pas d'attribut 'Recognizer'
À la place, essayez de taper moins de commandes
Collez le fichier .wav dans le répertoire de travail actuel
puis supprimez AUDIO_FILE
et saisissez:
avec sr.AudioFile ("english.wav") comme source
#!/usr/bin/env python3 import speech_recognition as sr # obtain path to "english.wav" in the same folder as this script #from os import path #AUDIO_FILE = path.join(path.dirname(path.realpath(__file__)), "english.wav") # AUDIO_FILE = path.join(path.dirname(path.realpath(__file__)), "french.aiff") # AUDIO_FILE = path.join(path.dirname(path.realpath(__file__)), "chinese.flac") # use the audio file as the audio source # paste the .wav file int current working directory r = sr.Recognizer() with sr.AudioFile("english.wav") as source: audio = r.record(source) # read the entire audio file
Bonjour, vous devriez fournir une explication de votre code avec l'extrait de code pour améliorer votre réponse