vosk-api
vosk-api copied to clipboard
UnboundLocalError: local variable 'monologue' referenced before assignment
In transcriber.py#L102 in the section where output_type == "json"
the local variable monologue
is referenced before assignment (see code and traceback below):
elif self.args.output_type == "json":
monologues = {"schemaVersion":"2.0", "monologues":[], "text":[]}
for part in result:
if part["text"] != "":
monologues["text"] += [part["text"]] # <- local variable 'monologue' referenced before assignment
for _, res in enumerate(result):
if not "result" in res:
continue
monologue = { "speaker": {"id": "unknown", "name": None}, "start": 0, "end": 0, "terms": []}
monologue["start"] = res["result"][0]["start"]
monologue["end"] = res["result"][-1]["end"]
monologue["terms"] = [{"confidence": t["conf"], "start": t["start"], "end": t["end"], "text": t["word"], "type": "WORD" } for t in res["result"]]
monologues["monologues"].append(monologue)
processed_result = json.dumps(monologues)
Traceback (most recent call last):
File "/home/map/.local/bin/vosk-transcriber", line 8, in <module>
sys.exit(main())
File "/home/map/.local/lib/python3.9/site-packages/vosk/transcriber/cli.py", line 86, in main
transcriber.process_task_list(task_list)
File "/home/map/.local/lib/python3.9/site-packages/vosk/transcriber/transcriber.py", line 195, in process_task_list
self.process_task_list_pool(task_list)
File "/home/map/.local/lib/python3.9/site-packages/vosk/transcriber/transcriber.py", line 191, in process_task_list_pool
pool.map(self.pool_worker, task_list)
File "/usr/lib/python3.9/multiprocessing/pool.py", line 364, in map
return self._map_async(func, iterable, mapstar, chunksize).get()
File "/usr/lib/python3.9/multiprocessing/pool.py", line 771, in get
raise self._value
File "/usr/lib/python3.9/multiprocessing/pool.py", line 125, in worker
result = (True, func(*args, **kwds))
File "/usr/lib/python3.9/multiprocessing/pool.py", line 48, in mapstar
return list(map(*args))
File "/home/map/.local/lib/python3.9/site-packages/vosk/transcriber/transcriber.py", line 170, in pool_worker
processed_result = self.format_result(result)
File "/home/map/.local/lib/python3.9/site-packages/vosk/transcriber/transcriber.py", line 104, in format_result
monologue["text"] += part["text"]
UnboundLocalError: local variable 'monologue' referenced before assignment