Artificial Intelligence Programming Lab(AIPLab) 討論區

程式語言摘要 => Python => 主題作者是: admin 於 七月 09, 2020, 03:22:43 pm

主題: SpeechRecognition
作者: admin七月 09, 2020, 03:22:43 pm
本文的目標是: 透過 麥克風 將我們說的話 顯示成文字
這將需要2個套件 "SpeechRecognition" 和 "pyaudio"
pip install SpeechRecognition
pip install PyAudio-0.2.11-cp37-cp37m-win_amd64.whl

程式碼: [Select]
#import library
import speech_recognition as sr

# Initialize recognizer class (for recognizing the speech)
r = sr.Recognizer()

# Reading Audio file as source
# listening the audio file and store in audio_text variable

with sr.AudioFile('I-dont-know.wav') as source:
    audio_text = r.listen(source)
# recoginize_() method will throw a request error if the API is unreachable, hence using exception handling
        # using google speech recognition
        text = r.recognize_google(audio_text)
        print('Converting audio transcripts into text ...')
         print('Sorry.. run again...')

#Adding french langauge option
text = r.recognize_google(audio_text, language = "fr-FR")