« 於: 七月 09, 2020, 03:22:43 pm »
本文的目標是: 透過 麥克風 將我們說的話 顯示成文字
這將需要2個套件 "SpeechRecognition" 和 "pyaudio"
pip install SpeechRecognition
pip install PyAudio-0.2.11-cp37-cp37m-win_amd64.whl
#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")