Artificial Intelligence Programming Lab(AIPLab) 討論區

Please login or register.

請輸入帳號, 密碼以及預計登入時間

新聞:

[慶賀]恭喜亞大獲《泰晤士報》亞洲最佳大學排名第83名,國內排名第十名-20170201

作者 主題: SpeechRecognition  (閱讀 28 次)

admin

  • 管理員
  • Hero Member
  • *****
  • 文章: 1803
    • 檢視個人資料
SpeechRecognition
« 於: 七月 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
    try:
       
        # using google speech recognition
        text = r.recognize_google(audio_text)
        print('Converting audio transcripts into text ...')
        print(text)
     
    except:
         print('Sorry.. run again...')


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

SimplePortal Classic 2.0.5