Files
ths-speech/python-server/speech.py
2018-08-16 02:36:59 +02:00

18 lines
567 B
Python

import speech_recognition as spr
def analyse(file_path):
''' returns the transcripted audio, or None if the analysis fails '''
recognizer = spr.Recognizer()
with spr.AudioFile(file_path) as source:
audio = recognizer.record(source)
try:
string = recognizer.recognize_google(audio)
except spr.UnknownValueError:
log.log("Audio file is broken or not an audio file")
return None
except spr.RequestError as e:
log.log("Could not connect to google API: {}".format(e))
return None
return string