KoljaB / RealtimeTTS

Converts text to speech in realtime
1.78k stars 159 forks source link

Crash on windows when use ConqEngine #21

Closed ILG2021 closed 9 months ago

ILG2021 commented 9 months ago

When I have a test with RealtimeTTS with the code below:

from RealtimeTTS import TextToAudioStream, CoquiEngine

engine = CoquiEngine()  # replace with your TTS engine
stream = TextToAudioStream(engine)
stream.feed("Hello world! How are you today?")
stream.play_async()

it crashes and give the error:

   engine = CoquiEngine()  # replace with your TTS engine
  File "D:\Python\xxxx\venv\lib\site-packages\RealtimeTTS\engines\base_engine.py", line 11, in __call__
    instance = super().__call__(*args, **kwargs)
  File "D:\Python\xxxx\venv\lib\site-packages\RealtimeTTS\engines\coqui_engine.py", line 96, in __init__
    self.synthesize_process.start()
  File "C:\Users\xxxx\AppData\Local\Programs\Python\Python310\lib\multiprocessing\process.py", line 121, in start
    self._popen = self._Popen(self)
  File "C:\Users\xxxx\AppData\Local\Programs\Python\Python310\lib\multiprocessing\context.py", line 224, in _Popen
    return _default_context.get_context().Process._Popen(process_obj)
  File "C:\Users\xxxx\AppData\Local\Programs\Python\Python310\lib\multiprocessing\context.py", line 336, in _Popen
    return Popen(process_obj)
  File "C:\Users\xxxx\AppData\Local\Programs\Python\Python310\lib\multiprocessing\popen_spawn_win32.py", line 45, in __init__
    prep_data = spawn.get_preparation_data(process_obj._name)
  File "C:\Users\xxxx\AppData\Local\Programs\Python\Python310\lib\multiprocessing\spawn.py", line 154, in get_preparation_data
    _check_not_importing_main()
  File "C:\Users\xxxx\AppData\Local\Programs\Python\Python310\lib\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.
KoljaB commented 9 months ago

Please try again with this code:

from RealtimeTTS import TextToAudioStream, CoquiEngine

if __name__ == '__main__':
    engine = CoquiEngine()  # replace with your TTS engine
    stream = TextToAudioStream(engine)
    stream.feed("Hello world! How are you today?")
    stream.play_async()

Sorry, I really need to rework the docs...