YarnGPT is a text-to-speech (TTS) model designed to synthesize Nigerian-accented English leveraging pure language modelling without external adapters or complex architectures, offering high-quality, natural, and culturally relevant speech synthesis for diverse applications.
The model can generate audio on its own but its better to use a voice to prompt the model, there are about 11 voices supported by default (6 males and 5 females ):
1# clone the YarnGPT repo to get access to the `audiotokenizer`
2!git clone https://github.com/saheedniyi02/yarngpt.git
3
4
5# install some necessary libraries
6!pip install outetts==0.2.3 uroman
7
8#import some important packages
9import os
10import re
11import json
12import torch
13import inflect
14import random
15import uroman as ur
16import numpy as np
17import torchaudio
18import IPython
19from transformers import AutoModelForCausalLM, AutoTokenizer
20from outetts.wav_tokenizer.decoder import WavTokenizer
21from yarngpt.audiotokenizer import AudioTokenizer
22
23
24# download the wavtokenizer weights and config (to encode and decode the audio)
25!wget https://huggingface.co/novateur/WavTokenizer-medium-speech-75token/resolve/main/wavtokenizer_mediumdata_frame75_3s_nq1_code4096_dim512_kmeans200_attn.yaml
26!gdown 1-ASeEkrn4HY49yZWHTASgfGFNXdVnLTt
27
28# model path and wavtokenizer weight path (the paths are assumed based on Google colab, a different environment might save the weights to a different location).
29hf_path="saheedniyi/YarnGPT"
30wav_tokenizer_config_path="/content/wavtokenizer_mediumdata_frame75_3s_nq1_code4096_dim512_kmeans200_attn.yaml"
31wav_tokenizer_model_path = "/content/wavtokenizer_large_speech_320_24k.ckpt"
32
33# create the AudioTokenizer object
34audio_tokenizer=AudioTokenizer(
35 hf_path,wav_tokenizer_model_path,wav_tokenizer_config_path
36)
37
38#load the model weights
39
40model = AutoModelForCausalLM.from_pretrained(hf_path,torch_dtype="auto").to(audio_tokenizer.device)
41
42# your input text
43text="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?"
44
45# creating a prompt, when creating a prompt, there is an optional `speaker_name` parameter, the possible speakers are "idera","emma","jude","osagie","tayo","zainab","joke","regina","remi","umar","chinenye" if no speaker is selected a speaker is chosen at random
46prompt=audio_tokenizer.create_prompt(text,"idera")
47
48# tokenize the prompt
49input_ids=audio_tokenizer.tokenize_prompt(prompt)
50
51# generate output from the model, you can tune the `.generate` parameters as you wish
52output = model.generate(
53 input_ids=input_ids,
54 temperature=0.1,
55 repetition_penalty=1.1,
56 max_length=4000,
57 )
58
59# convert the output to "audio codes"
60codes=audio_tokenizer.get_codes(output)
61
62# converts the codes to audio
63audio=audio_tokenizer.get_audio(codes)
64
65# play the audio
66IPython.display.Audio(audio,rate=24000)
67
68# save the audio
69torchaudio.save(f"audio.wav", audio, sample_rate=24000)
1!git clone https://github.com/saheedniyi02/yarngpt.git
2
3# install some necessary libraries
4!pip install outetts uroman trafilatura pydub
5
6import os
7import re
8import json
9import torch
10import inflect
11import random
12import requests
13import trafilatura
14import inflect
15import uroman as ur
16import numpy as np
17import torchaudio
18import IPython
19from pydub import AudioSegment
20from pydub.effects import normalize
21from transformers import AutoModelForCausalLM, AutoTokenizer
22from outetts.wav_tokenizer.decoder import WavTokenizer
23
24
25!wget https://huggingface.co/novateur/WavTokenizer-medium-speech-75token/resolve/main/wavtokenizer_mediumdata_frame75_3s_nq1_code4096_dim512_kmeans200_attn.yaml
26!gdown 1-ASeEkrn4HY49yZWHTASgfGFNXdVnLTt
27
28from yarngpt.audiotokenizer import AudioTokenizer
29
30tokenizer_path="saheedniyi/YarnGPT"
31wav_tokenizer_config_path="/content/wavtokenizer_mediumdata_frame75_3s_nq1_code4096_dim512_kmeans200_attn.yaml"
32wav_tokenizer_model_path = "/content/wavtokenizer_large_speech_320_24k.ckpt"
33
34
35
36audio_tokenizer=AudioTokenizer(
37 tokenizer_path,wav_tokenizer_model_path,wav_tokenizer_config_path
38 )
39
40
41model = AutoModelForCausalLM.from_pretrained(tokenizer_path,torch_dtype="auto").to(audio_tokenizer.device)
42
43
44def split_text_into_chunks(text, word_limit=25):
45 """
46 Function to split a long web page into reasonable chunks
47 """
48 sentences=[sentence.strip() for sentence in text.split('.') if sentence.strip()]
49 chunks=[]
50 for sentence in sentences:
51 chunks.append(".")
52 sentence_splitted=sentence.split(" ")
53 num_words=len(sentence_splitted)
54 start_index=0
55 if num_words>word_limit:
56 while start_index<num_words:
57 end_index=min(num_words,start_index+word_limit)
58 chunks.append(" ".join(sentence_splitted[start_index:start_index+word_limit]))
59 start_index=end_index
60 else:
61 chunks.append(sentence)
62 return chunks
63
64#Extracting the content of a webpage
65page=requests.get("https://punchng.com/expensive-feud-how-burna-boy-cubana-chief-priests-fight-led-to-dollar-rain/")
66content=trafilatura.extract(page.text)
67chunks=split_text_into_chunks(content)
68
69#Looping over the chunks and adding creating a large `all_codes` list
70all_codes=[]
71for i,chunk in enumerate(chunks):
72 print(i)
73 print("\n")
74 print(chunk)
75 if chunk==".":
76 #add silence for 0.25 seconds if we encounter a full stop
77 all_codes.extend([453]*20)
78 else:
79 prompt=audio_tokenizer.create_prompt(chunk,"chinenye")
80 input_ids=audio_tokenizer.tokenize_prompt(prompt)
81 output = model.generate(
82 input_ids=input_ids,
83 temperature=0.1,
84 repetition_penalty=1.1,
85 max_length=4000,
86 )
87 codes=audio_tokenizer.get_codes(output)
88 all_codes.extend(codes)
89
90
91# Converting to audio
92audio=audio_tokenizer.get_audio(all_codes)
93IPython.display.Audio(audio,rate=24000)
94torchaudio.save(f"news1.wav", audio, sample_rate=24000)
Generate Nigerian-accented English speech for experimental purposes.
The model is not suitable for generating speech in languages other than English or other accents.
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.
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.
Trained on a dataset of publicly available Nigerian movies, podcasts ( using the subtitle-audio pairs) and open source Nigerian-related audio data on Huggingface,
Audio files were preprocessed and resampled to 24Khz and tokenized using
wavtokenizer.
1@misc{yarngpt2025,
2 author = {Saheed Azeez},
3 title = {YarnGPT: Nigerian-Accented English Text-to-Speech Model},
4 year = {2025},
5 publisher = {Hugging Face},
6 url = {https://huggingface.co/SaheedAzeez/yarngpt}
7}