mirror of
https://github.com/FAUSheppy/ths-speech
synced 2025-12-07 00:11:37 +01:00
30 lines
875 B
Python
30 lines
875 B
Python
import speech_recognition as spr
|
|
import multiprocessing as mp
|
|
import os.path
|
|
import filesystem
|
|
import log
|
|
|
|
def async_create_transcript(filename):
|
|
mp.Process(target=create_and_save_transcript,args=(filename,)).start()
|
|
|
|
def create_and_save_transcript(filename):
|
|
transcript = analyse(filename)
|
|
filesystem.save_transcript(transcript)
|
|
|
|
def analyse(filename):
|
|
''' returns the transcripted audio, or None if the analysis fails '''
|
|
recognizer = spr.Recognizer()
|
|
with spr.AudioFile(filename) 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
|