Error when running example 'Usage' code

#6
by GourabHazra - opened

Traceback (most recent call last):
File "c:/Users/Admin/Desktop/Projects/NLP_Cron/cron_audio_test.py", line 27, in
generator = task.build_generator(model, cfg)
File "C:\Users\Admin\Desktop\Projects\NLP_Cron\cronenv\lib\site-packages\fairseq\tasks\text_to_speech.py", line 151, in build_generator
model = models[0]
TypeError: 'FastSpeech2Model' object is not subscriptable

I get this error when running on windows 10 in a virtual environment.

Use the model=models it worked for me

I had multiple issues on OSX. This code worked:

from fairseq.checkpoint_utils import load_model_ensemble_and_task_from_hf_hub
from fairseq.models.text_to_speech.hub_interface import TTSHubInterface
import soundfile as sf

models, cfg, task = load_model_ensemble_and_task_from_hf_hub(
    "facebook/fastspeech2-en-ljspeech",
    arg_overrides={"vocoder": "hifigan", "fp16": False}
)

TTSHubInterface.update_cfg_with_data_cfg(cfg, task.data_cfg)
generator = task.build_generator(models, cfg)

text = "Hello, this is a test run."

sample = TTSHubInterface.get_model_input(task, text)
wav, rate = TTSHubInterface.get_prediction(task, models[0], generator, sample)

sf.write("speech.wav", wav, samplerate=rate)

This finally worked for me in colab
Started a fresh runtime then,

!pip install fairseq
!pip install huggingface_hub
!pip install g2p_en

from fairseq.checkpoint_utils import load_model_ensemble_and_task_from_hf_hub
from fairseq.models.text_to_speech.hub_interface import TTSHubInterface
import soundfile as sf

models, cfg, task = load_model_ensemble_and_task_from_hf_hub(
   "facebook/fastspeech2-en-ljspeech",
   arg_overrides={"vocoder": "hifigan", "fp16": False}
)

TTSHubInterface.update_cfg_with_data_cfg(cfg, task.data_cfg)
generator = task.build_generator(models, cfg)

text = "Hello, this is a test run."

sample = TTSHubInterface.get_model_input(task, text)
wav, rate = TTSHubInterface.get_prediction(task, models[0], generator, sample)

sf.write("speech.wav", wav, samplerate=rate)
GourabHazra changed discussion status to closed

Finally right.

Sign up or log in to comment