python – How do you do google TTS in html in real time?-ThrowExceptions

Exception or error:
def synthesize_text(text):

    client = texttospeech.TextToSpeechClient()

    input_text = texttospeech.types.SynthesisInput(text=text)

    voice = texttospeech.types.VoiceSelectionParams(

    audio_config = texttospeech.types.AudioConfig(

    response = client.synthesize_speech(input_text, voice, audio_config)

    # The response's audio_content is binary.
    # Removing this because I do not care about writing the audio file
    # ----------------------------------------------------
    with open('output.mp3', 'wb') as out:
        print('Audio content written to file "output.mp3"')
    # ----------------------------------------------------
    # instead return the encoded audio_content to decode and play in Javascript
    return base64.b64encode(response.audio_content).decode('ascii')

def dialogflowweb(request):

    test_audio_content = synthesize_text('')
return render(request, 'hello.html', {'test_audio_content': test_audio_content})

test_audio_content = synthesize_text ('text')

You can put ‘text’ in the above function. I want to do TTS in real time in HTML. What should I do?

Using eel is the only way to load and read files.

How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *