YarnGPT2 is a text-to-speech (TTS) model designed to synthesize Nigerian-accented Languages (yoruba, igbo, hausa and english) leveraging pure language modelling without external adapters or complex architectures, offering high-quality, natural, and culturally relevant speech synthesis for diverse applications.
How to use (Colab)
The model can generate audio on its own but its better to use a voice to prompt the model:
Voices (arranged in order of perfomance and stability)
12!git clone https://github.com/saheedniyi02/yarngpt.git
34pip install outetts uroman
56import os
7import re
8import json
9import torch
10import inflect
11import random
12import uroman as ur
13import numpy as np
14import torchaudio
15import IPython
16from transformers import AutoModelForCausalLM, AutoTokenizer
17from outetts.wav_tokenizer.decoder import WavTokenizer
181920!wget https://huggingface.co/novateur/WavTokenizer-medium-speech-75token/resolve/main/wavtokenizer_mediumdata_frame75_3s_nq1_code4096_dim512_kmeans200_attn.yaml
21!gdown 1-ASeEkrn4HY49yZWHTASgfGFNXdVnLTt
222324from yarngpt.audiotokenizer import AudioTokenizerV2
2526tokenizer_path="saheedniyi/YarnGPT2"27wav_tokenizer_config_path="/content/wavtokenizer_mediumdata_frame75_3s_nq1_code4096_dim512_kmeans200_attn.yaml"28wav_tokenizer_model_path ="/content/wavtokenizer_large_speech_320_24k.ckpt"293031audio_tokenizer=AudioTokenizerV2(32 tokenizer_path,wav_tokenizer_model_path,wav_tokenizer_config_path
33)343536model = AutoModelForCausalLM.from_pretrained(tokenizer_path,torch_dtype="auto").to(audio_tokenizer.device)3738#change the text39text="The election was won by businessman and politician, Moshood Abiola, but Babangida annulled the results, citing concerns over national security."4041# change the language and voice42prompt=audio_tokenizer.create_prompt(text,lang="english",speaker_name="idera")4344input_ids=audio_tokenizer.tokenize_prompt(prompt)4546output = model.generate(47 input_ids=input_ids,48 temperature=0.1,49 repetition_penalty=1.1,50 max_length=4000,51#num_beams=5,# using a beam size helps for the local languages but not english52)5354codes=audio_tokenizer.get_codes(output)55audio=audio_tokenizer.get_audio(codes)56IPython.display.Audio(audio,rate=24000)57torchaudio.save(f"Sample.wav", audio, sample_rate=24000)58
Generate Nigerian-accented English speech for experimental purposes.
Out-of-Scope Use
The model is not suitable for generating speech in languages other than English or other accents.
Bias, Risks, and Limitations
The model may not capture the full diversity of Nigerian accents and could exhibit biases based on the training dataset. Also a lot of the text the model was trained on were automatically generated which could impact performance.
Recommendations
Users (both direct and downstream) should be made aware of the risks, biases, and limitations of the model. Feedback and diverse training data contributions are encouraged.
Speech Samples
Listen to samples generated by YarnGPT:
Input
Audio
Notes
Uhm, so, what was the inspiration behind your latest project? Like, was there a specific moment where you were like, 'Yeah, this is it!' Or, you know, did it just kind of, uh, come together naturally over time
Habeeb Okikiọla Olalomi Badmus ti ọpọ awọn ololufẹ rẹ mọ si Portable ti sọ fun ile ẹjọ majisireeti ti ipinlẹ Ogun wi pe ṣaka lara oun da, oun ko ni aisan tabi arun kankan lara.
Isi ụlọorụ Shell dị na Lọndọn na gọọmenti Naịjirịa ekwuputala ugboro ugboro na ọrụ ịsacha ogbe ndị lara n'iyi n'Ogoni bụ nke malitere ihe dịka afọ asatọ gara aga na-aga nke ọma.
Bisa ga dukkan alamu, haƙata cimma ruwa, dangane da koke-koken da tsofaffin ma'aikatan tarayya ke ta yi, a kan dimbin basukan wasu hakkokinsu da suke bi shekara da shekaru.
Trained on a dataset of publicly available Nigerian movies, podcasts ( using the subtitle-audio pairs) and open source Nigerian-related audio data on Huggingface,
Preprocessing
Audio files were preprocessed and resampled to 24Khz and tokenized using wavtokenizer.
Training Hyperparameters
Number of epochs: 5
batch_size: 4
Scheduler: linear schedule with warmup for 4 epochs, then linear decay to zero for the last epoch