viernes, 16 de agosto de 2024

google tts

 

import os


import logging

import google.cloud.texttospeech as tts

os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "/home/ambiorixg12/mycodes/google_speech/voice.json"


def text_to_wav(voice_name: str, text: str):

    language_code = "-".join(voice_name.split("-")[:2])

    text_input = tts.SynthesisInput(text=text)

    voice_params = tts.VoiceSelectionParams(

        language_code=language_code, name=voice_name

    )

    audio_config = tts.AudioConfig(audio_encoding=tts.AudioEncoding.LINEAR16)


    client = tts.TextToSpeechClient()

    response = client.synthesize_speech(

        input=text_input,

        voice=voice_params,

        audio_config=audio_config,

    )


    filename = f"{voice_name}.wav"

    with open(filename, "wb") as out:

        out.write(response.audio_content)

        print(f'Generated speech saved to "{filename}"')


text_to_wav("en-US-Studio-O", "What is the temperature in New York?")




https://codelabs.developers.google.com/codelabs/cloud-text-speech-python3#5

https://cloud.google.com/text-to-speech/docs/libraries?hl=es-419


https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-texttospeech/samples/generated_samples

No hay comentarios:

Publicar un comentario