ฉันจะใช้ไฟล์เสียงเป็นแหล่งเสียงใน SpeechRecognition ใน Python ได้อย่างไร

ฉันใช้ speech_recognition.AudioFile ใน Python 3.6 แต่มีการระบุข้อผิดพลาดนี้:

AttributeError: module 'speech_recognition' has no attribute 'AudioFile'

นี่คือรหัสของฉัน:

#!/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

นอกจากนี้ฉันใช้ speech_recognition 3.1.3


person hamed baziyad    schedule 04.12.2019    source แหล่งที่มา


คำตอบ (3)


คุณสามารถเปลี่ยนเป็น SpeechRecognition เวอร์ชันใหม่กว่านี้ได้หรือไม่ รหัสของคุณทำงานได้อย่างราบรื่นโดยใช้เวอร์ชันล่าสุด แต่เวอร์ชัน 3.1.3 ดูเหมือนจะยังไม่มีฟีเจอร์นั้นและทำให้เกิดข้อผิดพลาดสำหรับฉันเช่นกัน

ชื่อไฟล์ของสคริปต์ของคุณเรียกว่า Speech_recognition.py หรือไม่ มีคนประสบปัญหานั้น: การรู้จำคำพูด: AttributeError: โมดูล 'speech_recognition' ไม่มีแอตทริบิวต์ 'Recognizer'

person John    schedule 04.12.2019

ให้ลองพิมพ์คำสั่งน้อยลงแทน

วางไฟล์ .wav ลงในไดเร็กทอรีการทำงานปัจจุบัน

จากนั้นลบ AUDIO_FILE

และพิมพ์:

โดยมี sr.AudioFile("english.wav") เป็นแหล่งที่มา

person vasantha raj    schedule 31.12.2019

person    schedule
comment
สวัสดี คุณควรให้คำอธิบายโค้ดของคุณพร้อมกับตัวอย่างข้อมูลเพื่อปรับปรุงคำตอบของคุณ - person Kevin; 24.02.2020