Generar diálogos con varios interlocutores

En esta página se describe cómo crear un diálogo con varios interlocutores con la función de texto a voz.

Puedes generar audio con varios interlocutores para crear un diálogo. Esto puede ser útil para entrevistas, narraciones interactivas, videojuegos, plataformas de e-learning y soluciones de accesibilidad.

Se admite la siguiente voz para el audio con varios interlocutores:

  • en-US-Studio-Multispeaker
    • Ponente: R
    • Ponente: S
    • Ponente: T
    • Ponente: U


Ejemplo: Esta muestra es un audio que se ha generado usando varias voces.

Ejemplo de cómo usar el marcado de varios interlocutores

Este es un ejemplo que muestra cómo usar el marcado de varios oradores.

Python

Para saber cómo instalar y usar la biblioteca de cliente de Text-to-Speech, consulta el artículo sobre las bibliotecas de cliente de Text-to-Speech. Para obtener más información, consulta la documentación de referencia de la API Text-to-Speech Python.

Para autenticarte en Text-to-Speech, configura las credenciales predeterminadas de la aplicación. Para obtener más información, consulta el artículo Configurar la autenticación en un entorno de desarrollo local.

"""Synthesizes speech for multiple speakers.
Make sure to be working in a virtual environment.
"""
from google.cloud import texttospeech_v1beta1 as texttospeech

# Instantiates a client
client = texttospeech.TextToSpeechClient()

multi_speaker_markup = texttospeech.MultiSpeakerMarkup(
    turns=[
        texttospeech.MultiSpeakerMarkup.Turn(
            text="I've heard that the Google Cloud multi-speaker audio generation sounds amazing!",
            speaker="R",
        ),
        texttospeech.MultiSpeakerMarkup.Turn(
            text="Oh? What's so good about it?", speaker="S"
        ),
        texttospeech.MultiSpeakerMarkup.Turn(text="Well..", speaker="R"),
        texttospeech.MultiSpeakerMarkup.Turn(text="Well what?", speaker="S"),
        texttospeech.MultiSpeakerMarkup.Turn(
            text="Well, you should find it out by yourself!", speaker="R"
        ),
        texttospeech.MultiSpeakerMarkup.Turn(
            text="Alright alright, let's try it out!", speaker="S"
        ),
    ]
)

# Set the text input to be synthesized
synthesis_input = texttospeech.SynthesisInput(
    multi_speaker_markup=multi_speaker_markup
)

# Build the voice request, select the language code ('en-US') and the voice
voice = texttospeech.VoiceSelectionParams(
    language_code="en-US", name="en-US-Studio-MultiSpeaker"
)

# Select the type of audio file you want returned
audio_config = texttospeech.AudioConfig(
    audio_encoding=texttospeech.AudioEncoding.MP3
)

# Perform the text-to-speech request on the text input with the selected
# voice parameters and audio file type
response = client.synthesize_speech(
    input=synthesis_input, voice=voice, audio_config=audio_config
)

# The response's audio_content is binary.
with open("output.mp3", "wb") as out:
    # Write the response to the output file.
    out.write(response.audio_content)
    print('Audio content written to file "output.mp3"')