mirror of
https://github.com/FAUSheppy/ths-speech
synced 2025-12-09 13:18:34 +01:00
Initial
This commit is contained in:
17
python-server/speech.py
Normal file
17
python-server/speech.py
Normal file
@@ -0,0 +1,17 @@
|
||||
import speech_recognition as spr
|
||||
def analyse(file_path):
|
||||
''' returns the transcripted audio, or None if the analysis fails '''
|
||||
recognizer = spr.Recognizer()
|
||||
with sr.AudioFile(file_path) as source:
|
||||
audio = r.record(source)
|
||||
|
||||
try:
|
||||
string = r.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
|
||||
Reference in New Issue
Block a user