KoljaB / RealtimeSTT

A robust, efficient, low-latency speech-to-text library with advanced voice activity detection, wake word activation and instant transcription.
MIT License
1.59k stars 145 forks source link

An attempt has been made to start a new process before the current process has finished its bootstrapping phase #89

Closed she7ata7 closed 3 weeks ago

she7ata7 commented 1 month ago

I'm trying to use STT but sometimes it works and sometimes no, Please tell me what I need to do to fix that.

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib/python3.10/multiprocessing/spawn.py", line 116, in spawn_main
    exitcode = _main(fd, parent_sentinel)
  File "/usr/lib/python3.10/multiprocessing/spawn.py", line 125, in _main
    prepare(preparation_data)
  File "/usr/lib/python3.10/multiprocessing/spawn.py", line 236, in prepare
    _fixup_main_from_path(data['init_main_from_path'])
  File "/usr/lib/python3.10/multiprocessing/spawn.py", line 287, in _fixup_main_from_path
    main_content = runpy.run_path(main_path,
  File "/usr/lib/python3.10/runpy.py", line 289, in run_path
    return _run_module_code(code, init_globals, run_name,
  File "/usr/lib/python3.10/runpy.py", line 96, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "/usr/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/home/legionrtx/Desktop/ai_assistant/main.py", line 2, in <module>
    from sip.sip_client import SipClient
  File "/home/legionrtx/Desktop/ai_assistant/sip/sip_client.py", line 5, in <module>
    from sip.account import Account
  File "/home/legionrtx/Desktop/ai_assistant/sip/account.py", line 2, in <module>
    from .call import Call
  File "/home/legionrtx/Desktop/ai_assistant/sip/call.py", line 5, in <module>
    from .AudioMediaPort import AudioMediaPort
  File "/home/legionrtx/Desktop/ai_assistant/sip/AudioMediaPort.py", line 16, in <module>
    class AudioMediaPort(pj.AudioMediaPort):
  File "/home/legionrtx/Desktop/ai_assistant/sip/AudioMediaPort.py", line 41, in AudioMediaPort
    tts = TTS_CoquiEngine()
  File "/home/legionrtx/Desktop/ai_assistant/tts/coqui_engine.py", line 7, in __init__
    self.engine = CoquiEngine()
  File "/home/legionrtx/.local/lib/python3.10/site-packages/RealtimeTTS/engines/base_engine.py", line 11, in __call__
    instance = super().__call__(*args, **kwargs)
  File "/home/legionrtx/.local/lib/python3.10/site-packages/RealtimeTTS/engines/coqui_engine.py", line 197, in __init__
    self.create_worker_process()
  File "/home/legionrtx/.local/lib/python3.10/site-packages/RealtimeTTS/engines/coqui_engine.py", line 256, in create_worker_process
    self.synthesize_process.start()
  File "/usr/lib/python3.10/multiprocessing/process.py", line 121, in start
    self._popen = self._Popen(self)
  File "/usr/lib/python3.10/multiprocessing/context.py", line 224, in _Popen
    return _default_context.get_context().Process._Popen(process_obj)
  File "/usr/lib/python3.10/multiprocessing/context.py", line 288, in _Popen
    return Popen(process_obj)
  File "/usr/lib/python3.10/multiprocessing/popen_spawn_posix.py", line 32, in __init__
    super().__init__(process_obj)
  File "/usr/lib/python3.10/multiprocessing/popen_fork.py", line 19, in __init__
    self._launch(process_obj)
  File "/usr/lib/python3.10/multiprocessing/popen_spawn_posix.py", line 42, in _launch
    prep_data = spawn.get_preparation_data(process_obj._name)
  File "/usr/lib/python3.10/multiprocessing/spawn.py", line 154, in get_preparation_data
    _check_not_importing_main()
  File "/usr/lib/python3.10/multiprocessing/spawn.py", line 134, in _check_not_importing_main
    raise RuntimeError('''
RuntimeError: 
        An attempt has been made to start a new process before the
        current process has finished its bootstrapping phase.
        This probably means that you are not using fork to start your
        child processes and you have forgotten to use the proper idiom
        in the main module:
            if __name__ == '__main__':
                freeze_support()
                ...
        The "freeze_support()" line can be omitted if the program
        is not going to be frozen to produce an executable.
she7ata7 commented 1 month ago
from RealtimeTTS import TextToAudioStream, CoquiEngine, GTTSVoice
import time

class TTS_CoquiEngine:

    def __init__(self):
        self.engine = CoquiEngine()
        self.stream = TextToAudioStream(self.engine)

    def __dummy_generator(self):
        yield "Hey guys! These here are realtime spoken sentences based on local text synthesis."

    def play_stream(self):
        # Record the start time
        start_time = time.time()

        print("Starting to play stream")
        self.stream.feed(self.__dummy_generator()).play(log_synthesized_text=True)

    def command_to_stream(self, text, on_audio_chunk_callback):
        self.stream.feed(text)
        self.stream.play(on_audio_chunk=on_audio_chunk_callback, muted=True)

    def command_to_wav(self, command, file_path):
        self.stream.feed(command)
        self.stream.play(output_wavfile = file_path, muted= True)
        return file_path

    def shutdown(self):
        self.engine.shutdown()

if __name__ == '__main__':
    tts = TTS_CoquiEngine()
    tts.play_stream()
    tts.shutdown()