Search code examples
pythonpython-3.xgoogle-cloud-platformtext-to-speechgoogle-speech-api

converting Japanese text to speech using python APO


I need to convert my Japanese sentences into audio files and save them separately. I have found the gtts package that can do this with English and some other languages. But it seems Japanese is not supported.

Is there any alternative way for Japanese?

Thanks in advance


Solution

  • I know there's a program in BASH that does text-to-speech.
    sudo apt install translate-shell https://github.com/soimort/translate-shell

    trans -p -lang ja "hello"
    

    I only mention that, because you could call it with a subprocess, if need be.



    The one you mentioned seems to run fine though. https://www.thepythoncode.com/article/convert-text-to-speech-in-python

    #! /usr/bin/env python3
    
    ##  sudo apt install ffmpeg espeak libespeak1 python-gst-1.0
    ##  pip3 install gTTS pyttsx3 playsound
    
    import gtts
    from playsound import playsound
    
    tts = gtts .gTTS( '感嘆詞', lang='ja' )  ##  request google to get synthesis
    
    tts .save( 'hello.mp3' )  ##  save audio
    playsound( 'hello.mp3' )  ##  play audio
    
    ##  print( gtts .lang .tts_langs() )