mirror of
https://github.com/rakuri255/UltraSinger.git
synced 2026-12-02 09:58:09 +09:00
23 lines
964 B
Python
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) |