音声認識のサンプルです.

目次

  1. サンプル

サンプル

import os
from contextlib import redirect_stdout
import speech_recognition as sr

recognizer = sr.Recognizer()

try:
with sr.Microphone() as mic:
print("Listening...")
voice = recognizer.listen(mic)
with redirect_stdout(open(os.devnull, 'w')):
voice_text = recognizer.recognize_google(voice, language="ja-JP")
print(voice_text)
except:
print('テキストに起こせませんでした.')