Код: Выделить всё
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""""""
# Uncomment the emotion you want to apply
ssml += f"
{chunk}" # happy
# ssml += f"{chunk}" # romantic
# ssml += f"{chunk}" # hopeful
# ssml += f"{chunk}" # neutral
# ssml += f"{chunk}" # disappointed
# ssml += f"{chunk}" # angry
# ssml += f"{chunk}" # fearful
# ssml += f"{chunk}" # sad
# ssml += f"{chunk}" # devastated
ssml += ""
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)
Код: Выделить всё
AttributeError Traceback (most recent call last)
in ()
53
54 # Convert text to speech with the selected emotion
---> 55 synthesize_speech(sample_text)
1 frames
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
сделайте одиночные и несколько динамиков, возможно, кто-нибудь знает решение или посоветует мне использовать другую модель, я хочу бесплатную
Подробнее здесь: https://stackoverflow.com/questions/790 ... -happens-i