Files
UltraSinger/moduls/Speech_Recognition/VoskTranscribedData.py
T
2023-01-27 22:54:14 +01:00

23 lines
964 B
Python

class VoskTranscribedData:
""" A class representing a word from the JSON format for vosk speech recognition API """
# Code from here: https://towardsdatascience.com/speech-recognition-with-timestamps-934ede4234b2
def __init__(self, dict):
'''
Parameters:
dict (dict) dictionary from JSON, containing:
conf (float): degree of confidence, from 0 to 1
end (float): end time of the pronouncing the word, in seconds
start (float): start time of the pronouncing the word, in seconds
word (str): recognized word
'''
self.conf = dict["conf"]
self.end = dict["end"]
self.start = dict["start"]
self.word = dict["word"]
def to_string(self):
''' Returns a string describing this instance '''
return "{:20} from {:.2f} sec to {:.2f} sec, confidence is {:.2f}%".format(
self.word, self.start, self.end, self.conf*100)