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.
34 lines
1010 B
Python
34 lines
1010 B
Python
7 years ago
|
#!/usr/bin/env python3
|
||
7 years ago
|
# https://github.com/Uberi/speech_recognition/blob/master/examples/audio_transcribe.py
|
||
7 years ago
|
|
||
|
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
|
||
|
|
||
7 years ago
|
|
||
7 years ago
|
# 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"]
|
||
|
|
||
7 years ago
|
# recognize speech using Sphinx
|
||
7 years ago
|
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)
|
||
|
|