[Python] can't generate the speech from library tts of coqui-tts and this error happens in...

Discussão em 'Python' iniciado por Stack, Setembro 27, 2024.

  1. Stack

    Stack Membro Participativo

    from TTS.utils.manage import ModelManager
    from TTS.utils.synthesizer import Synthesizer

    from google.colab import files

    Initialize the model manager and load the models

    model_name = "tts_models/en/ljspeech/tacotron2-DDC"

    vocoder_name = "vocoder_models/en/ljspeech/hifigan_v2"

    model_manager = ModelManager()

    model_path, config_path, _ = model_manager.download_model(model_name)

    vocoder_path, vocoder_config_path, _ = model_manager.download_model(vocoder_name)

    Create the synthesizer object

    synthesizer = Synthesizer(model_path, config_path, vocoder_path, vocoder_config_path, use_cuda=False)

    Generate dynamic SSML based on manually chosen emotion

    def generate_dynamic_ssml(chunk):

    ssml = f"""<speak version='1.0' xmlns='http://www.w3.org/2001/10/synthesis' xml:lang='en-US'>"""



    # Uncomment the emotion you want to apply

    ssml += f"<prosody pitch='+10%' rate='fast'><emphasis level='moderate'>{chunk}</emphasis></prosody>" # happy

    # ssml += f"<prosody pitch='+5%' rate='medium'><emphasis level='strong'>{chunk}</emphasis></prosody>" # romantic

    # ssml += f"<prosody pitch='+7%' rate='medium'><emphasis level='moderate'>{chunk}</emphasis></prosody>" # hopeful

    # ssml += f"<prosody pitch='default' rate='medium'><emphasis level='none'>{chunk}</emphasis></prosody>" # neutral

    # ssml += f"<prosody pitch='-5%' rate='slow'><emphasis level='moderate'>{chunk}</emphasis></prosody>" # disappointed

    # ssml += f"<prosody pitch='-10%' rate='fast'><emphasis level='strong'>{chunk}</emphasis></prosody>" # angry

    # ssml += f"<prosody pitch='-10%' rate='slow'><emphasis level='strong'>{chunk}</emphasis></prosody>" # fearful

    # ssml += f"<prosody pitch='-15%' rate='slow'><emphasis level='strong'>{chunk}</emphasis></prosody>" # sad

    # ssml += f"<prosody pitch='-20%' rate='very slow'><emphasis level='strong'>{chunk}</emphasis></prosody>" # devastated



    ssml += "</speak>"

    return ssml

    Function to synthesize speech for each chunk

    def synthesize_speech(text):

    # Generate SSML for the whole text with a manually selected emotion

    ssml = generate_dynamic_ssml(text)



    # Synthesize the text

    wav = synthesizer.tts(ssml)



    # Save the output file

    output_file = "output_with_emotion.wav"

    synthesizer.save_wav(wav, output_file)



    # Download the file to the local machine

    files.download(output_file)

    Example usage

    if name == "main":

    sample_text = """I am so happy to see you! You make my heart race with joy and love."""



    # Convert text to speech with the selected emotion

    synthesize_speech(sample_text)


    code using tacotron2 model and vocoder hifigen after that I use the synthesizer library ssml that change the pitch of the voice to make it like emotion

    AttributeError Traceback (most recent call last)

    <ipython-input-8-2698293d91f3> in <cell line: 51>()

    53

    54 # Convert text to speech with the selected emotion

    ---> 55 synthesize_speech(sample_text)

    1 frames

    <ipython-input-8-2698293d91f3> in synthesize_speech(text)

    39

    40 # Synthesize the text

    ---> 41 wav = synthesizer.tts(ssml)

    42

    43 # Save the output file

    /usr/local/lib/python3.10/dist-packages/TTS/utils/synthesizer.py in tts(self, text, speaker_name, language_name, speaker_wav, style_wav, style_text, reference_wav, reference_speaker_name, split_sentences, **kwargs)

    320 speaker_id = self.tts_model.speaker_manager.name_to_id[speaker_name]

    321 # handle Neon models with single speaker.

    --> 322 elif len(self.tts_model.speaker_manager.name_to_id) == 1:

    323 speaker_id = list(self.tts_model.speaker_manager.name_to_id.values())[0]

    324 elif not speaker_name and not speaker_wav:

    AttributeError: 'NoneType' object has no attribute 'name_to_id' that is the error



    that tts code using coqui-tts that make emotional tts so the following error always apper and I have tried to make the code single and multi speakers

    make single and multi speakers maybe someone know the solution or advice me to use another model I want it a free one

    Continue reading...

Compartilhe esta Página