You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
OuNuPo/src/ttssr_transcribe.py

34 lines
1010 B
Python

#!/usr/bin/env python3
# https://github.com/Uberi/speech_recognition/blob/master/examples/audio_transcribe.py
import speech_recognition as sr
import sys
from termcolor import cprint, colored
from os import path
import random
a1 = sys.argv[1] #same as $1 so when you run python3 audio_transcribe.py FOO ... argv[1] is FOO
# print ("transcribing", a1, file=sys.stderr)
AUDIO_FILE = path.join(path.dirname(path.realpath(__file__)), a1) # before it was english.wav
# 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
color = ["white", "yellow"]
on_color = ["on_red", "on_magenta", "on_blue", "on_grey"]
# recognize speech using Sphinx
try:
cprint( r.recognize_sphinx(audio), random.choice(color), random.choice(on_color))
# print( r.recognize_sphinx(audio))
except sr.UnknownValueError:
print("uknown")
except sr.RequestError as e:
print("Sphinx error; {0}".format(e))
# sleep (1)