Created
March 7, 2021 09:31
-
-
Save dauuricus/5fa7a906bb53dee2d79b8d90cd372f0d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import json | |
| import pandas as pd | |
| import datetime | |
| def fmttime(sec): | |
| secs = sec#millisecs / 1000.0 | |
| d = datetime.timedelta(seconds=secs) | |
| t = (datetime.datetime.min + d).time() | |
| milli = t.strftime('%f')[:3] | |
| value = t.strftime('%H:%M:%S,') + milli | |
| return value | |
| with open('vosk.json','r') as f: | |
| #lines = f.readlines() | |
| jso = pd.read_json(f) | |
| #j = pd.io.json.json_normalize(jso) | |
| caption=[] | |
| lineNum=1 | |
| for i,v in enumerate(jso.result): | |
| laststart = v['start'] | |
| lastend = v['end'] | |
| caption.append(v['word']) | |
| if len(caption) == 1: | |
| start = v['start'] | |
| if v['start'] - lastend > 1: | |
| print(lineNum) | |
| print(fmttime(laststart),'-->',fmttime(lastend)) | |
| temp = caption.pop() | |
| print(*caption) | |
| print() | |
| caption.clear() | |
| start = v['end'] | |
| lineNum +=1 | |
| caption.append(temp) | |
| if v['end'] - start > 2: | |
| print(lineNum) | |
| print(fmttime(start),'-->',fmttime(v['end'])) | |
| print(*prev) | |
| print(*caption) | |
| print() | |
| prev = copy.deepcopy(caption) | |
| caption.clear() | |
| start = v['end'] | |
| lineNum +=1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment