### Install EmotiVoice with Training Dependencies Source: https://github.com/netease-youdao/emotivoice/blob/main/data/DataBaker/README.md Install the EmotiVoice package with all necessary dependencies for training. Alternatively, clone the repository and install in editable mode. ```bash pip install EmotiVoice[train] # or git clone https://github.com/netease-youdao/EmotiVoice pip install -e .[train] ``` -------------------------------- ### Install Dependencies and Run OpenAI-compatible TTS API Source: https://github.com/netease-youdao/emotivoice/blob/main/README.md Install the necessary Python packages for the OpenAI-compatible TTS API and then run the Uvicorn server to start the API. Ensure you have fastapi, pydub, uvicorn, and pyrubberband installed. ```sh pip install fastapi pydub uvicorn[standard] pyrubberband uvicorn openaiapi:app --reload ``` -------------------------------- ### Install Streamlit for UI Source: https://github.com/netease-youdao/emotivoice/blob/main/README_小白安装教程.md Installs the Streamlit library, which is required to run the interactive UI of EmotiVoice. ```bash pip install streamlit ``` -------------------------------- ### Install FFmpeg on Ubuntu Source: https://github.com/netease-youdao/emotivoice/blob/main/README_小白安装教程.md Install FFmpeg on Ubuntu systems to resolve 'FileNotFoundError: [Errno 2] No such file or directory: 'ffmpeg''. Verify the installation by running 'ffmpeg -version'. ```bash sudo apt update sudo apt install ffmpeg ``` ```bash ffmpeg -version ``` -------------------------------- ### Install Streamlit and Run Interactive Demo Source: https://github.com/netease-youdao/emotivoice/blob/main/README.md Install the Streamlit library and run the interactive TTS demo page. This is a convenient way to test the TTS functionality. ```sh pip install streamlit streamlit run demo_page.py ``` -------------------------------- ### Install EmotiVoice Training Dependencies Source: https://context7.com/netease-youdao/emotivoice/llms.txt Install the necessary packages for training EmotiVoice, either via pip or from source. This enables fine-tuning on custom data. ```bash # Install training dependencies pip install EmotiVoice[train] # or from source: git clone https://github.com/netease-youdao/EmotiVoice pip install -e .[train] ``` -------------------------------- ### Install git-lfs on Ubuntu Source: https://github.com/netease-youdao/emotivoice/blob/main/README_小白安装教程.md Installs git and git-lfs on Ubuntu systems, which is required for cloning large model files. ```bash sudo apt update sudo apt install git sudo apt-get install git-lfs ``` -------------------------------- ### Docker Quickstart for EmotiVoice Source: https://context7.com/netease-youdao/emotivoice/llms.txt Quickly run EmotiVoice using Docker. Requires an NVIDIA GPU and NVIDIA Container Toolkit. Exposes a web UI on port 8501 and an OpenAI-compatible API on port 8000. ```sh # Pull and run the latest Docker image (exposes web UI on :8501, OpenAI API on :8000) docker pull syq163/emoti-voice:latest docker run -dp 127.0.0.1:8501:8501 -p 127.0.0.1:8000:8000 syq163/emoti-voice:latest # Open web demo # http://localhost:8501 # OpenAI-compatible TTS endpoint # http://localhost:8000/v1/audio/speech ``` -------------------------------- ### Run EmotiVoice Streamlit Web Demo Source: https://context7.com/netease-youdao/emotivoice/llms.txt Launches an interactive browser-based TTS demo. Requires Streamlit installation. Opens the demo at http://localhost:8501. ```bash pip install streamlit streamlit run demo_page.py # Opens http://localhost:8501 in the browser ``` -------------------------------- ### Install FFmpeg on CentOS Source: https://github.com/netease-youdao/emotivoice/blob/main/README_小白安装教程.md Install FFmpeg on CentOS systems to resolve 'FileNotFoundError: [Errno 2] No such file or directory: 'ffmpeg''. Verify the installation by running 'ffmpeg -version'. ```bash sudo yum install epel-release sudo yum install ffmpeg ``` ```bash ffmpeg -version ``` -------------------------------- ### Install Core Python Dependencies Source: https://github.com/netease-youdao/emotivoice/blob/main/README_小白安装教程.md Installs essential Python libraries for EmotiVoice, including PyTorch, Transformers, and NLTK data. ```bash pip install torch torchaudio pip install numpy numba scipy transformers soundfile yacs g2p_en jieba pypinyin pypinyin_dict python -m nltk.downloader "averaged_perceptron_tagger_eng" ``` -------------------------------- ### Replicate Cog Predictor Setup Source: https://context7.com/netease-youdao/emotivoice/llms.txt Provides a Predictor class for cloud deployment on Replicate. Automatically downloads model weights on first setup. ```python # cog.yaml defines the Cog container; prediction is run via: ``` -------------------------------- ### Full EmotiVoice Installation Source: https://github.com/netease-youdao/emotivoice/blob/main/README.md Install EmotiVoice using Conda and pip. This includes setting up a Python environment, installing core dependencies like PyTorch, and downloading NLTK data. ```sh conda create -n EmotiVoice python=3.8 -y conda activate EmotiVoice pip install torch torchaudio pip install numpy numba scipy transformers soundfile yacs g2p_en jieba pypinyin pypinyin_dict python -m nltk.downloader "averaged_perceptron_tagger_eng" ``` -------------------------------- ### Install git-lfs on CentOS Source: https://github.com/netease-youdao/emotivoice/blob/main/README_小白安装教程.md Installs git and git-lfs on CentOS systems, necessary for handling large file storage in Git repositories. ```bash sudo yum update sudo yum install git sudo yum install git-lfs ``` -------------------------------- ### Install API Service Dependencies Source: https://github.com/netease-youdao/emotivoice/blob/main/README_小白安装教程.md Installs Python packages required for running the EmotiVoice API service, including FastAPI and Uvicorn. ```bash pip install fastapi pydub uvicorn[standard] pyrubberband ``` -------------------------------- ### Full Python Installation for EmotiVoice Source: https://context7.com/netease-youdao/emotivoice/llms.txt Install EmotiVoice and its dependencies using Conda and Pip. Includes downloading NLTK data for English G2P and pretrained models. ```sh conda create -n EmotiVoice python=3.8 -y conda activate EmotiVoice pip install torch torchaudio pip install numpy numba scipy transformers soundfile yacs g2p_en jieba pypinyin pypinyin_dict # Download NLTK data required for English G2P python -m nltk.downloader "averaged_perceptron_tagger_eng" # Download pretrained SimBERT model git lfs install git lfs clone https://huggingface.co/WangZeJun/simbert-base-chinese WangZeJun/simbert-base-chinese # Download pretrained EmotiVoice checkpoints git clone https://www.modelscope.cn/syq163/outputs.git ``` -------------------------------- ### Finetune LJSpeech Model with Torchrun Source: https://github.com/netease-youdao/emotivoice/blob/main/data/LJspeech/README.md Use this command to start the fine-tuning process for the acoustic model and vocoder. Ensure the config folder and pretrained model path are correctly specified. ```bash torchrun \ --nproc_per_node=1 \ --master_port 8008 \ train_am_vocoder_joint.py \ --config_folder exp/LJspeech/config \ --load_pretrained_model True ``` -------------------------------- ### Install MFA Environment Source: https://github.com/netease-youdao/emotivoice/blob/main/data/DataBaker/README.md Installs the necessary Conda and pip packages for the Montreal Forced Aligner (MFA) environment. This step is optional for the DataBaker recipe but useful if preparing your own data. ```bash # MFA environment install conda install -c conda-forge kaldi sox librosa biopython praatio tqdm requests colorama pyyaml pynini openfst baumwelch ngram postgresql -y pip install pgvector hdbscan montreal-forced-aligner ``` -------------------------------- ### Clone EmotiVoice Repository Source: https://github.com/netease-youdao/emotivoice/blob/main/README_小白安装教程.md Initializes git-lfs and clones the EmotiVoice project repository. Ensure git-lfs is installed first. ```bash git lfs install git lfs clone https://github.com/netease-youdao/EmotiVoice.git ``` -------------------------------- ### Start EmotiVoice API Service Source: https://github.com/netease-youdao/emotivoice/blob/main/README_小白安装教程.md Starts the EmotiVoice API service using Uvicorn on port 6006. The API documentation can be accessed at the service address plus '/docs'. ```bash uvicorn openaiapi:app --reload --port 6006 ``` -------------------------------- ### Synthesize Speech with EmotiVoice Source: https://context7.com/netease-youdao/emotivoice/llms.txt This code demonstrates how to load models, get style and content embeddings, and synthesize speech using the JETS generator. Ensure all necessary configurations and models are loaded before execution. ```python with open(config.model_config_path, 'r') as fin: conf = CONFIG.load_cfg(fin) conf.n_vocab = config.n_symbols conf.n_speaker = config.speaker_n_labels tokenizer = AutoTokenizer.from_pretrained(config.bert_path) style_encoder = StyleEncoder(config) generator = JETSGenerator(conf).to(device) generator.eval() def get_style_embedding(prompt_text, tokenizer, style_encoder): tokens = tokenizer([prompt_text], return_tensors="pt") with torch.no_grad(): output = style_encoder( input_ids=tokens["input_ids"], token_type_ids=tokens["token_type_ids"], attention_mask=tokens["attention_mask"], ) return output["pooled_output"].cpu().squeeze().numpy() style_emb = get_style_embedding("Happy", tokenizer, style_encoder) content_emb = get_style_embedding("Hello world", tokenizer, style_encoder) phoneme_ids = [token2id[ph] for ph in phoneme_sequence.split()] sequence = torch.tensor(phoneme_ids, device=device).long().unsqueeze(0) sequence_len = torch.tensor([len(phoneme_ids)], device=device) with torch.no_grad(): output = generator( inputs_ling=sequence, inputs_style_embedding=torch.tensor(style_emb, device=device).unsqueeze(0), input_lengths=sequence_len, inputs_content_embedding=torch.tensor(content_emb, device=device).unsqueeze(0), inputs_speaker=torch.tensor([speaker2id["8051"]], device=device), alpha=1.0, ) audio = output["wav_predictions"].squeeze() * MAX_WAV_VALUE audio = audio.cpu().numpy().astype("int16") sf.write("output.wav", audio, samplerate=config.sampling_rate) ``` -------------------------------- ### EmotiVoice Training Data Format Source: https://context7.com/netease-youdao/emotivoice/llms.txt Example of the JSONL format required for training data. Each line is a JSON object containing audio path, speaker information, text, and prompt. ```jsonl // data/train/datalist.jsonl — one JSON object per line {"key": "LJ002-0020", "wav_path": "data/LJspeech/wavs/LJ002-0020.wav", "speaker": "LJ", "text": ["", "[IH0]", "[N]", "engsp1", "[EY0]", "[T]", "[IY1]", "[N]", "engsp1", "[TH]", "[ER1]", "[T]", "[IY1]", "[N]", ".", ""], "original_text": "In 1813", "prompt": "common"} {"key": "LJ002-0021", "wav_path": "data/LJspeech/wavs/LJ002-0021.wav", "speaker": "LJ", "text": ["", "[AE1]", "[T]", "engsp1", "[DH]", "[AH0]", "engsp1", "[EY1]", "[JH]", ".", ""], "original_text": "At the age.", "prompt": "happy"} ``` -------------------------------- ### Clone simbert-base-chinese Model Source: https://github.com/netease-youdao/emotivoice/wiki/Pretrained-models Download the 'simbert-base-chinese' model using Git LFS. Ensure Git LFS is installed before cloning. ```sh git lfs install git lfs clone https://huggingface.co/WangZeJun/simbert-base-chinese WangZeJun/simbert-base-chinese ``` -------------------------------- ### Install Specific typing_extensions Version Source: https://github.com/netease-youdao/emotivoice/blob/main/README_小白安装教程.md Resolve 'ImportError: cannot import name 'Doc' from 'typing_extensions'' by installing a specific version of typing_extensions. This version is tested to work with fastapi v0.104.1. ```bash pip install typing_extensions==4.8.0 --force-reinstall ``` -------------------------------- ### Prepare and Launch EmotiVoice Training Source: https://context7.com/netease-youdao/emotivoice/llms.txt Steps to prepare the experiment directory, optionally tune hyperparameters in the config file, and launch the training process using `torchrun`. ```bash # Step 1: Prepare experiment directory from data directory python prepare_for_training.py \ --data_dir data/LJspeech \ --exp_dir exp/LJspeech # Step 2: (Optional) Edit exp/LJspeech/config/config.py to tune hyperparameters # Key params: batch_size=16, lr=1e-3, iters_per_checkpoint=10000 # Step 3: Launch training (fine-tune from pretrained EmotiVoice weights) torchrun \ --nproc_per_node=1 \ --master_port 8018 \ train_am_vocoder_joint.py \ --config_folder exp/LJspeech/config \ --load_pretrained_model True ``` -------------------------------- ### Run TensorBoard for Monitoring Training Source: https://github.com/netease-youdao/emotivoice/blob/main/data/DataBaker/README.md Launch TensorBoard to visualize training progress and metrics. Point the log directory to your experiment's output folder. ```bash tensorboard --logdir=exp/DataBaker ``` -------------------------------- ### Launch TensorBoard for Monitoring Source: https://github.com/netease-youdao/emotivoice/blob/main/data/LJspeech/README.md Run this command to launch TensorBoard, which allows you to monitor training progress. The log directory should point to your experiment's output folder. ```bash tensorboard --logdir=exp/LJspeech ``` -------------------------------- ### Prepare Data for Training Source: https://github.com/netease-youdao/emotivoice/blob/main/data/DataBaker/README.md Execute this script to prepare your dataset for model training. Ensure to review and adjust configuration paths in `exp/DataBaker/config/config.py` for data directories, training files, and batch size. ```bash python prepare_for_training.py --data_dir data/DataBaker --exp_dir exp/DataBaker ``` -------------------------------- ### Finetune Model with Joint AM-Vocoder Training Source: https://github.com/netease-youdao/emotivoice/blob/main/data/DataBaker/README.md Initiate the finetuning process for your model using joint acoustic model and vocoder training. This command requires specifying the configuration folder and whether to load a pretrained model. ```bash torchrun \ --nproc_per_node=1 \ --master_port 8008 \ train_am_vocoder_joint.py \ --config_folder exp/DataBaker/config \ --load_pretrained_model True ``` -------------------------------- ### Run EmotiVoice UI Source: https://github.com/netease-youdao/emotivoice/blob/main/README_小白安装教程.md Launches the EmotiVoice web UI using Streamlit. Access the UI via the provided server address. ```bash streamlit run demo_page.py --server.port 6006 --logger.level debug ``` -------------------------------- ### Download and Prepare DataBaker Raw Data Source: https://github.com/netease-youdao/emotivoice/blob/main/data/DataBaker/README.md Create a directory for raw DataBaker data and download the dataset from the provided URL, placing the extracted folder within the raw data directory. ```bash mkdir data/DataBaker/raw # download # please download the data from https://en.data-baker.com/datasets/freeDatasets/, and place the extracted BZNSYP folder under data/DataBaker/raw ``` -------------------------------- ### Navigate to Project Directory Source: https://github.com/netease-youdao/emotivoice/blob/main/README_小白安装教程.md Changes the current directory to the root of the EmotiVoice project after cloning. ```bash cd EmotiVoice ``` -------------------------------- ### MFA Data Preparation Steps Source: https://github.com/netease-youdao/emotivoice/blob/main/data/LJspeech/README.md A series of commands to prepare the dataset, text, and special tokens for MFA alignment. ```bash # MFA Step1 python mfa/step1_create_dataset.py \ --data_dir data/LJspeech # MFA Step2 python mfa/step2_prepare_data.py \ --dataset_dir data/LJspeech/mfa \ --wav data/LJspeech/mfa/wav.txt \ --speaker data/LJspeech/mfa/speaker.txt \ --text data/LJspeech/mfa/text.txt # MFA Step3 python mfa/step3_prepare_special_tokens.py \ --special_tokens data/LJspeech/mfa/special_token.txt # MFA Step4 python mfa/step4_convert_text_to_phn.py \ --text data/LJspeech/mfa/text.txt \ --special_tokens data/LJspeech/mfa/special_token.txt \ --output data/LJspeech/mfa/text.txt # MFA Step5 python mfa/step5_prepare_alignment.py \ --wav data/LJspeech/mfa/wav.txt \ --speaker data/LJspeech/mfa/speaker.txt \ --text data/LJspeech/mfa/text.txt \ --special_tokens data/LJspeech/mfa/special_token.txt \ --pronounciation_dict data/LJspeech/mfa/mfa_pronounciation_dict.txt \ --output_dir data/LJspeech/mfa/lab # MFA Step6 mfa validate \ --overwrite \ --clean \ --single_speaker \ data/LJspeech/mfa/lab \ data/LJspeech/mfa/mfa_pronounciation_dict.txt mfa train \ --overwrite \ --clean \ --single_speaker \ data/LJspeech/mfa/lab \ data/LJspeech/mfa/mfa_pronounciation_dict.txt \ data/LJspeech/mfa/mfa/mfa_model.zip \ data/LJspeech/mfa/TextGrid mfa align \ --single_speaker \ data/LJspeech/mfa/lab \ data/LJspeech/mfa/mfa_pronounciation_dict.txt \ data/LJspeech/mfa/mfa/mfa_model.zip \ data/LJspeech/mfa/TextGrid # MFA Step7 python mfa/step7_gen_alignment_from_textgrid.py \ --wav data/LJspeech/mfa/wav.txt \ --speaker data/LJspeech/mfa/speaker.txt \ --text data/LJspeech/mfa/text.txt \ --special_tokens data/LJspeech/mfa/special_token.txt \ --text_grid data/LJspeech/mfa/TextGrid \ --aligned_wav data/LJspeech/mfa/aligned_wav.txt \ --aligned_speaker data/LJspeech/mfa/aligned_speaker.txt \ --duration data/LJspeech/mfa/duration.txt \ --aligned_text data/LJspeech/mfa/aligned_text.txt \ --reassign_sp True # MFA Step8 python mfa/step8_make_data_list.py \ --wav data/LJspeech/mfa/aligned_wav.txt \ --speaker data/LJspeech/mfa/aligned_speaker.txt \ --text data/LJspeech/mfa/aligned_text.txt \ --duration data/LJspeech/mfa/duration.txt \ --datalist_path data/LJspeech/mfa/datalist.jsonl # MFA Step9 python mfa/step9_datalist_from_mfa.py \ --data_dir data/LJspeech ``` -------------------------------- ### Prepare Data for Training Source: https://github.com/netease-youdao/emotivoice/blob/main/data/LJspeech/README.md Prepares the LJSpeech dataset for training by organizing data and experiment directories. ```bash python prepare_for_training.py --data_dir data/LJspeech --exp_dir exp/LJspeech ``` -------------------------------- ### MFA Data Preparation Steps Source: https://github.com/netease-youdao/emotivoice/blob/main/data/DataBaker/README.md A series of Python scripts to prepare data for MFA alignment, including creating datasets, preparing speaker and text files, generating phonemes, and creating pronunciation dictionaries. ```bash # MFA Step1 python mfa/step1_create_dataset.py \ --data_dir data/DataBaker # MFA Step2 python mfa/step2_prepare_data.py \ --dataset_dir data/DataBaker/mfa \ --wav data/DataBaker/mfa/wav.txt \ --speaker data/DataBaker/mfa/speaker.txt \ --text data/DataBaker/mfa/text.txt # MFA Step3 python mfa/step3_prepare_special_tokens.py \ --special_tokens data/DataBaker/mfa/special_token.txt # MFA Step4 python mfa/step4_convert_text_to_phn.py \ --text data/DataBaker/mfa/text.txt \ --special_tokens data/DataBaker/mfa/special_token.txt \ --output data/DataBaker/mfa/text.txt # MFA Step5 python mfa/step5_prepare_alignment.py \ --wav data/DataBaker/mfa/wav.txt \ --speaker data/DataBaker/mfa/speaker.txt \ --text data/DataBaker/mfa/text.txt \ --special_tokens data/DataBaker/mfa/special_token.txt \ --pronounciation_dict data/DataBaker/mfa/mfa_pronounciation_dict.txt \ --output_dir data/DataBaker/mfa/lab # MFA Step6 mfa validate \ --overwrite \ --clean \ --single_speaker \ data/DataBaker/mfa/lab \ data/DataBaker/mfa/mfa_pronounciation_dict.txt mfa train \ --overwrite \ --clean \ --single_speaker \ data/DataBaker/mfa/lab \ data/DataBaker/mfa/mfa_pronounciation_dict.txt \ data/DataBaker/mfa/mfa/mfa_model.zip \ data/DataBaker/mfa/TextGrid mfa align \ --single_speaker \ data/DataBaker/mfa/lab \ data/DataBaker/mfa/mfa_pronounciation_dict.txt \ data/DataBaker/mfa/mfa/mfa_model.zip \ data/DataBaker/mfa/TextGrid # MFA Step7 python mfa/step7_gen_alignment_from_textgrid.py \ --wav data/DataBaker/mfa/wav.txt \ --speaker data/DataBaker/mfa/speaker.txt \ --text data/DataBaker/mfa/text.txt \ --special_tokens data/DataBaker/mfa/special_token.txt \ --text_grid data/DataBaker/mfa/TextGrid \ --aligned_wav data/DataBaker/mfa/aligned_wav.txt \ --aligned_speaker data/DataBaker/mfa/aligned_speaker.txt \ --duration data/DataBaker/mfa/duration.txt \ --aligned_text data/DataBaker/mfa/aligned_text.txt \ --reassign_sp True # MFA Step8 python mfa/step8_make_data_list.py \ --wav data/DataBaker/mfa/aligned_wav.txt \ --speaker data/DataBaker/mfa/aligned_speaker.txt \ --text data/DataBaker/mfa/aligned_text.txt \ --duration data/DataBaker/mfa/duration.txt \ --datalist_path data/DataBaker/mfa/datalist.jsonl # MFA Step9 python mfa/step9_datalist_from_mfa.py \ --data_dir data/DataBaker ``` -------------------------------- ### Run EmotiVoice Docker Image Source: https://github.com/netease-youdao/emotivoice/blob/main/README.md Use this command to run the EmotiVoice Docker image. Ensure you have NVidia container toolkit set up. The web interface will be available at http://localhost:8501. ```sh docker run -dp 127.0.0.1:8501:8501 syq163/emoti-voice:latest ``` -------------------------------- ### Importing EmotiVoice Python Modules Source: https://context7.com/netease-youdao/emotivoice/llms.txt Demonstrates how to import core EmotiVoice modules for direct library integration. ```python from frontend import g2p_cn_en from models.prompt_tts_modified.jets import JETSGenerator ``` -------------------------------- ### Download and Extract LJSpeech Dataset Source: https://github.com/netease-youdao/emotivoice/blob/main/data/LJspeech/README.md Creates a directory for raw LJSpeech data and downloads/extracts the dataset. ```bash mkdir data/LJspeech/raw # download wget -P data/LJspeech/raw http://data.keithito.com/data/speech/LJSpeech-1.1.tar.bz2 # extract tar -xjf data/LJspeech/raw/LJSpeech-1.1.tar.bz2 -C data/LJspeech/raw ``` -------------------------------- ### Inference with Fine-tuned EmotiVoice Checkpoint Source: https://context7.com/netease-youdao/emotivoice/llms.txt Run inference using a fine-tuned checkpoint. Specify the config folder and the checkpoint name to generate audio from test data. ```bash # Step 4: Inference with fine-tuned checkpoint python inference_am_vocoder_exp.py \ --config_folder exp/LJspeech/config \ --checkpoint g_00010000 \ --test_file data/inference/text # Output: exp/LJspeech/test_audio/audio/g_00010000/1.wav ... # Reference: ~1–2 hours per 10,000 steps on RTX 3090 / A40 ``` -------------------------------- ### EmotiVoice Configuration Class Source: https://context7.com/netease-youdao/emotivoice/llms.txt Python code demonstrating how to import and use the `Config` class from `config.joint.config` to access various runtime parameters. ```python from config.joint.config import Config config = Config() # Key path attributes print(config.bert_path) # 'WangZeJun/simbert-base-chinese' print(config.token_list_path) # '.../data/youdao/text/tokenlist' print(config.speaker2id_path) # '.../data/youdao/text/speaker2' print(config.output_directory) # '.../outputs' print(config.model_config_path) # '.../config/joint/config.yaml' # Speaker and token vocabulary sizes (auto-loaded from files) print(config.speaker_n_labels) # e.g. 2088 (number of available voices) print(config.n_symbols) # size of phoneme token vocabulary # List all available speaker IDs print(config.speakers[:10]) # ['8051', '8052', '8053', ...] # Audio settings print(config.sampling_rate) # 16000 Hz print(config.filter_length) # 1024 (STFT) print(config.n_mel_channels) # 80 # Training hyperparameters print(config.batch_size) # 16 print(config.lr) # 0.001 print(config.iters_per_checkpoint) # 10000 ``` -------------------------------- ### Update and Run EmotiVoice Docker Image Source: https://github.com/netease-youdao/emotivoice/blob/main/README.md Pull the latest EmotiVoice Docker image and run it, exposing both the web UI and the OpenAI-compatible TTS API. The web UI is at http://localhost:8501 and the API at http://localhost:8000. ```sh docker pull syq163/emoti-voice:latest docker run -dp 127.0.0.1:8501:8501 -p 127.0.0.1:8000:8000 syq163/emoti-voice:latest ``` -------------------------------- ### Synthesize Speech using Python OpenAI SDK Source: https://context7.com/netease-youdao/emotivoice/llms.txt Integrate with the EmotiVoice TTS API using the OpenAI Python SDK. Configure the client with the local server's base URL and use the `audio.speech.create` method to synthesize speech with various parameters. ```python from openai import OpenAI client = OpenAI( base_url="http://127.0.0.1:8000/v1", api_key="not-needed", ) response = client.audio.speech.create( model="emoti-voice", voice="8051", input="Hello! I'm so excited to meet you today.", extra_body={ "prompt": "Excited", "language": "zh_us", "response_format": "mp3", "speed": 1.0, }, ) response.stream_to_file("output.mp3") ``` -------------------------------- ### Perform Inference with Trained Model Source: https://github.com/netease-youdao/emotivoice/blob/main/data/DataBaker/README.md Generate synthesized speech using your finetuned model. Specify the configuration folder, the checkpoint to use, and the text file containing speaker information. ```bash TEXT=data/inference/text python inference_am_vocoder_exp.py \ --config_folder exp/DataBaker/config \ --checkpoint g_00010000 \ --test_file $TEXT ``` -------------------------------- ### Download NLTK Data Packages Source: https://github.com/netease-youdao/emotivoice/blob/main/README_小白安装教程.md Create and run this Python script to download missing NLTK data packages like 'averaged_perceptron_tagger' and 'cmudict', which can cause 'BadZipFile' errors. Ensure you have internet access. ```python import nltk print(nltk.data.path) nltk.download('averaged_perceptron_tagger') nltk.download('cmudict') ``` ```python python download.py ``` -------------------------------- ### Download simbert-base-chinese Model (Option 1) Source: https://github.com/netease-youdao/emotivoice/blob/main/README_小白安装教程.md Clones the simbert-base-chinese model files using git-lfs. This is one of two methods for downloading required models. ```bash git lfs clone https://huggingface.co/WangZeJun/simbert-base-chinese WangZeJun/simbert-base-chinese ``` -------------------------------- ### Manually Download NLTK Data Packages Source: https://github.com/netease-youdao/emotivoice/blob/main/README_小白安装教程.md If automatic download fails, manually download the required zip files from the provided URLs and place them in the nltk_data directory. Ensure the directory structure is correct after extraction. ```bash https://raw.githubusercontent.com/nltk/nltk_data/gh-pages/packages/taggers/averaged_perceptron_tagger.zip ``` ```bash https://raw.githubusercontent.com/nltk/nltk_data/gh-pages/packages/corpora/cmudict.zip ``` -------------------------------- ### Alternative Clone simbert-base-chinese Model Source: https://github.com/netease-youdao/emotivoice/wiki/Pretrained-models An alternative command to download the 'simbert-base-chinese' model from ModelScope. ```sh git clone https://www.modelscope.cn/syq163/WangZeJun.git ``` -------------------------------- ### Run Streamlit with CORS Disabled Source: https://github.com/netease-youdao/emotivoice/blob/main/README_小白安装教程.md Use this command to run the Streamlit UI if you encounter CORS-related 'Please wait...' or blank page errors. Consider re-enabling CORS with correct configurations afterward. ```bash streamlit run demo_page.py --server.port 6006 --logger.level debug --server.enableCORS=false ``` -------------------------------- ### Clone TTS Pretrained Models Source: https://github.com/netease-youdao/emotivoice/wiki/Pretrained-models Use this command to download TTS models with over 2000 voices. Ensure the directory structure matches the provided image. ```sh git clone https://www.modelscope.cn/syq163/outputs.git ``` -------------------------------- ### Synthesize Speech using cURL (WAV Output with Speed Adjustment) Source: https://context7.com/netease-youdao/emotivoice/llms.txt Use cURL to synthesize speech with a specified voice, prompt, and language, adjusting the playback speed. The output will be a WAV file. Ensure the server is running. ```sh curl -s http://127.0.0.1:8000/v1/audio/speech \ -H "Content-Type: application/json" \ -d '{ "input": "This is spoken at 1.5 times normal speed.", "voice": "8051", "prompt": "Excited", "speed": 1.5, "response_format": "wav" }' \ --output fast_speech.wav ``` -------------------------------- ### Core Synthesis Function for Streamlit Demo Source: https://context7.com/netease-youdao/emotivoice/llms.txt Core synthesis function used by the Streamlit demo. Loads models, processes text, and returns audio samples. Requires specific imports and model loading. ```python import streamlit as st from frontend import g2p_cn_en, ROOT_DIR, read_lexicon, G2p from config.joint.config import Config import torch, numpy as np config = Config() lexicon = read_lexicon(f"{ROOT_DIR}/lexicon/librispeech-lexicon.txt") g2p = G2p() @st.cache_resource def get_models(): # Loads StyleEncoder + JETSGenerator + tokenizer from checkpoints # Returns (style_encoder, generator, tokenizer, token2id, speaker2id) ... def synthesize_demo(speaker_id, emotion_prompt, text_content): """ Args: speaker_id (str): e.g. "8051" — pick from config.speakers list emotion_prompt (str): e.g. "Happy", "Sad", "Excited", or descriptive sentence text_content (str): Chinese, English, or mixed text to synthesize Returns: np.ndarray: int16 audio samples at 16000 Hz """ models = get_models() phonemes = g2p_cn_en(text_content, g2p, lexicon) audio = tts( name=0, text=phonemes, prompt=emotion_prompt, content=text_content, speaker=speaker_id, models=models ) return audio # play with st.audio(audio, sample_rate=config.sampling_rate) # Streamlit UI snippet speakers = config.speakers # list of all 2000+ speaker IDs speaker = st.selectbox("Speaker ID", speakers) prompt = st.text_input("Emotion Prompt", "Happy") content = st.text_input("Text", "欢迎使用易魔声 TTS engine!") if st.button("Synthesize"): audio = synthesize_demo(speaker, prompt, content) st.audio(audio, sample_rate=16000) ``` -------------------------------- ### Create and Activate Conda Environment Source: https://github.com/netease-youdao/emotivoice/blob/main/data/DataBaker/README.md Use this command to create a new conda environment named EmotiVoice with Python 3.8 and activate it. ```bash conda create -n EmotiVoice python=3.8 -y conda activate EmotiVoice ``` -------------------------------- ### Python TTS Demo using EmotiVoice HTTP API Source: https://github.com/netease-youdao/emotivoice/wiki/HTTP-API This Python script demonstrates how to make a Text-to-Speech request using the EmotiVoice HTTP API. Ensure APP_KEY, APP_SECRET, PATH, q, and voiceName are correctly configured before running. ```python import http.client import json def createRequest(APP_KEY, APP_SECRET, PATH, q, voiceName): conn = http.client.HTTPSConnection("ai.youdao.com") payload = json.dumps({ "q": q, "voiceName": voiceName, "speed": 0, "volume": 0, "audeoFormat": "wav" }) headers = { 'Content-Type': 'application/json', 'appKey': APP_KEY, 'appSecret': APP_SECRET } conn.request("POST", "/tts/v1/wav", payload, headers) res = conn.getresponse() return res.read() ``` -------------------------------- ### Preprocess LJSpeech Data Source: https://github.com/netease-youdao/emotivoice/blob/main/data/LJspeech/README.md Runs scripts to clean raw data and extract phonemes for the LJSpeech dataset. ```bash # format data python data/LJspeech/src/step1_clean_raw_data.py \ --data_dir data/LJspeech # get phoneme python data/LJspeech/src/step2_get_phoneme.py \ --data_dir data/LJspeech ``` -------------------------------- ### Format and Extract Phonemes from DataBaker Data Source: https://github.com/netease-youdao/emotivoice/blob/main/data/DataBaker/README.md These commands format the raw DataBaker data and extract phoneme labels. The second command can optionally generate phonemes if only text labels are available, but this is not needed for the DataBaker recipe. ```bash # format data python data/DataBaker/src/step1_clean_raw_data.py \ --data_dir data/DataBaker # get phoneme python data/DataBaker/src/step2_get_phoneme.py \ --data_dir data/DataBaker ``` -------------------------------- ### Synthesize Speech using EmotiVoice HTTP API Source: https://context7.com/netease-youdao/emotivoice/llms.txt Call the EmotiVoice HTTP API to synthesize speech. Requires APP_KEY and APP_SECRET. Saves audio to a local file. ```python import requests from utils.AuthV3Util import addAuthParams APP_KEY = 'your_app_id' # 应用ID from Youdao console APP_SECRET = 'your_app_secret' # 应用密钥 from Youdao console PATH = 'output.mp3' # Local path to save synthesized audio def synthesize(text, voice_name='Maria Kasper', fmt='mp3'): """ Call the EmotiVoice HTTP API to synthesize speech. Args: text (str): Input text (max 1000 bytes) voice_name (str): Voice name from EmotiVoice voice list fmt (str): Output format, 'mp3' or 'wav' Voice options (Chinese, emotionally rich): 'shudingli' - Male, 20-year-old audiobook voice 'shuyanshi' - Male, middle-aged audiobook voice 'shuwudi' - Female, teenage girl audiobook voice 'youxiaofu' - Female, warm customer service voice """ data = {'q': text, 'voiceName': voice_name, 'format': fmt} addAuthParams(APP_KEY, APP_SECRET, data) # Adds auth signature in-place headers = {'Content-Type': 'application/x-www-form-urlencoded'} response = requests.post('https://openapi.youdao.com/ttsapi', data, headers) content_type = response.headers.get('Content-Type', '') if 'audio' in content_type: with open(PATH, 'wb') as f: f.write(response.content) print(f"Audio saved to: {PATH}") else: # API returned an error body (JSON with error code) print("Error:", response.content.decode('utf-8')) # Example usage synthesize( text='Emoti-Voice - a Multi-Voice and Prompt-Controlled TTS Engine,大家好', voice_name='Maria Kasper', fmt='mp3' ) # Expected output: Audio file saved as 'output.mp3' within ~1 second ``` -------------------------------- ### OpenAI-Compatible TTS API Source: https://context7.com/netease-youdao/emotivoice/llms.txt A FastAPI server that exposes a POST endpoint matching OpenAI's TTS API contract. Accepts JSON with input, voice, prompt, language, response_format, and speed. Returns binary audio (WAV or MP3). ```APIDOC ## POST /v1/audio/speech ### Description Synthesizes speech from text with optional emotional prompts and playback speed adjustments. ### Method POST ### Endpoint /v1/audio/speech ### Parameters #### Request Body - **input** (string) - Required - Text to synthesize. - **voice** (string) - Optional - Speaker ID from speaker list. Defaults to '8051'. - **prompt** (string) - Optional - Emotion/style prompt, e.g. "Happy", "Sad". Defaults to empty string. - **language** (string) - Optional - Language code. Defaults to 'zh_us'. - **model** (string) - Optional - Model name. Defaults to 'emoti-voice'. - **response_format** (string) - Optional - Output audio format. Accepts 'mp3' or 'wav'. Defaults to 'mp3'. - **speed** (float) - Optional - Playback speed multiplier. Defaults to 1.0. ### Request Example ```json { "input": "Welcome to EmotiVoice, the emotional TTS engine.", "voice": "8051", "prompt": "Happy", "language": "zh_us", "response_format": "mp3", "speed": 1.0 } ``` ### Response #### Success Response (200) - Binary audio data (MP3 or WAV format). ### Request Example (Python SDK) ```python from openai import OpenAI client = OpenAI( base_url="http://127.0.0.1:8000/v1", api_key="not-needed", # no auth required for local server ) response = client.audio.speech.create( model="emoti-voice", voice="8051", # speaker ID; see voice wiki for full list input="Hello! I\'m so excited to meet you today.", extra_body={ "prompt": "Excited", "language": "zh_us", "response_format": "mp3", "speed": 1.0, }, ) response.stream_to_file("output.mp3") ``` ``` -------------------------------- ### Streamlit Web Demo for EmotiVoice TTS Source: https://context7.com/netease-youdao/emotivoice/llms.txt Launches an interactive browser-based TTS demo using Streamlit. Users can select a speaker, input an emotion prompt and text, and synthesize speech with in-browser playback and download options. ```APIDOC ## Streamlit Web Demo ### Description An interactive web interface for EmotiVoice TTS powered by Streamlit. ### Usage 1. Install Streamlit: `pip install streamlit` 2. Run the demo: `streamlit run demo_page.py` 3. Access the demo in your browser at `http://localhost:8501`. ### Core Synthesis Function (`synthesize_demo`) #### Arguments - **speaker_id** (str): The ID of the speaker to use (e.g., "8051"). - **emotion_prompt** (str): A text prompt describing the desired emotion (e.g., "Happy", "Sad"). - **text_content** (str): The text to be synthesized (supports Chinese, English, or mixed). #### Returns - **np.ndarray**: An array of 16-bit integer audio samples at 16000 Hz. ### Streamlit UI Snippet ```python import streamlit as st # Assume config, get_models, synthesize_demo are defined elsewhere speakers = config.speakers # List of available speaker IDs speaker = st.selectbox("Speaker ID", speakers) prompt = st.text_input("Emotion Prompt", "Happy") content = st.text_input("Text", "欢迎使用易魔声 TTS engine!") if st.button("Synthesize"): audio = synthesize_demo(speaker, prompt, content) st.audio(audio, sample_rate=16000) ``` ``` -------------------------------- ### Synthesize Speech using EmotiVoice HTTP API Source: https://context7.com/netease-youdao/emotivoice/llms.txt This function demonstrates how to call the EmotiVoice HTTP API to synthesize speech from text. It handles authentication, sends the request, and saves the audio to a local file or prints an error message. ```APIDOC ## POST /ttsapi ### Description Synthesizes speech from the provided text using the EmotiVoice HTTP API. ### Method POST ### Endpoint https://openapi.youdao.com/ttsapi ### Parameters #### Query Parameters - **q** (str) - Required - Input text to synthesize (max 1000 bytes). - **voiceName** (str) - Optional - The name of the voice to use. Defaults to 'Maria Kasper'. - **format** (str) - Optional - The output audio format, either 'mp3' or 'wav'. Defaults to 'mp3'. ### Request Example ```python import requests from utils.AuthV3Util import addAuthParams APP_KEY = 'your_app_id' APP_SECRET = 'your_app_secret' data = { 'q': 'Emoti-Voice - a Multi-Voice and Prompt-Controlled TTS Engine,大家好', 'voiceName': 'Maria Kasper', 'format': 'mp3' } addAuthParams(APP_KEY, APP_SECRET, data) headers = {'Content-Type': 'application/x-www-form-urlencoded'} response = requests.post('https://openapi.youdao.com/ttsapi', data, headers) if 'audio' in response.headers.get('Content-Type', ''): with open('output.mp3', 'wb') as f: f.write(response.content) print("Audio saved to: output.mp3") else: print("Error:", response.content.decode('utf-8')) ``` ### Response #### Success Response (200) - **Content-Type**: 'audio/mpeg' or 'audio/wav' - The synthesized audio data. #### Error Response - **Content-Type**: 'application/json' - A JSON object containing error details. ### Voice Options - **shudingli**: Male, 20-year-old audiobook voice - **shuyanshi**: Male, middle-aged audiobook voice - **shuwudi**: Female, teenage girl audiobook voice - **youxiaofu**: Female, warm customer service voice ``` -------------------------------- ### Batch CLI Inference for EmotiVoice Source: https://context7.com/netease-youdao/emotivoice/llms.txt Performs batch TTS inference from a text file. Input lines must be pipe-delimited: speaker_id|emotion_prompt|phoneme_sequence|original_text. Output WAV files are saved in a specified directory. ```sh # Step 1: Generate phoneme input file # Input line format: speaker_id|prompt|original_text # Example data/inference/text contents: # 8051|Happy| [IH0] [M] [AA1] ... |Emoti-Voice - a Multi-Voice TTS Engine # Step 2: Run inference TEXT=data/inference/text python inference_am_vocoder_joint.py \ --logdir prompt_tts_open_source_joint \ --config_folder config/joint \ --checkpoint g_00140000 \ --test_file $TEXT # Output WAV files are written to: # outputs/prompt_tts_open_source_joint/test_audio/audio/g_00140000/1.wav # outputs/prompt_tts_open_source_joint/test_audio/audio/g_00140000/2.wav # ... ``` ```python # Python equivalent (core inference logic) import torch, numpy as np, soundfile as sf from models.prompt_tts_modified.jets import JETSGenerator from models.prompt_tts_modified.simbert import StyleEncoder from transformers import AutoTokenizer from config.joint.config import Config from yacs import config as CONFIG config = Config() device = torch.device("cuda" if torch.cuda.is_available() else "cpu") MAX_WAV_VALUE = 32768.0 ``` -------------------------------- ### EmotiVoice Text-to-Speech API Source: https://github.com/netease-youdao/emotivoice/wiki/HTTP-API This section details the EmotiVoice HTTP API for text-to-speech conversion. It requires application registration on Zhiyun, obtaining an App ID and App Secret, and then using these credentials to make API calls. The API supports Chinese text input and allows customization of voice parameters. ```APIDOC ## EmotiVoice Text-to-Speech API ### Description This API allows users to convert text into speech using EmotiVoice technology. It requires authentication via an application ID and secret obtained from the Zhiyun platform. ### Method POST ### Endpoint /api/v1/tts ### Parameters #### Query Parameters - **appId** (string) - Required - Your application ID. - **appSecret** (string) - Required - Your application secret. - **q** (string) - Required - The text to be synthesized. Limited to 1000 bytes (approx. 200-300 Chinese characters). - **voiceName** (string) - Optional - The name of the voice to use. Refer to EmotiVoice's [List of Voices](https://github.com/netease-youdao/EmotiVoice/wiki/😊-voice-wiki-page) for available options. - **path** (string) - Required - The path where the generated audio file will be saved. ### Request Example ```python { "appId": "YOUR_APP_ID", "appSecret": "YOUR_APP_SECRET", "q": "你好,这是一个测试。", "voiceName": "shudingli", "path": "output.wav" } ``` ### Response #### Success Response (200) - **audioContent** (string) - The synthesized speech audio content. - **message** (string) - A success message. #### Response Example ```json { "audioContent": "/path/to/saved/audio.wav", "message": "Success" } ``` #### Error Response (4xx/5xx) - **errorCode** (string) - An error code. - **errorMessage** (string) - A description of the error. ``` -------------------------------- ### Synthesize Speech using cURL (MP3 Output) Source: https://context7.com/netease-youdao/emotivoice/llms.txt Use cURL to send a POST request to the TTS API endpoint to synthesize speech with an emotion prompt and receive the output as an MP3 file. Ensure the server is running. ```sh curl -s http://127.0.0.1:8000/v1/audio/speech \ -H "Content-Type: application/json" \ -d '{ "input": "Welcome to EmotiVoice, the emotional TTS engine.", "voice": "8051", "prompt": "Happy", "language": "zh_us", "response_format": "mp3", "speed": 1.0 }' \ --output speech.mp3 ``` -------------------------------- ### Predict Text to Speech with EmotiVoice Source: https://context7.com/netease-youdao/emotivoice/llms.txt Use the `cog predict` command to synthesize speech from text, specifying emotion, content, language, and speaker. The model handles English and Chinese. ```bash cog predict -i prompt="Happy" -i content="Hello world" -i language="English" -i speaker="8051" ```