Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnboundLocalError: local variable 'monologue' referenced before assignment #1536

Open
me-kell opened this issue Mar 9, 2024 · 0 comments
Open

Comments

@me-kell
Copy link

me-kell commented Mar 9, 2024

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant