Skip to main content

TTS

Project description

kokoro

An inference library for Kokoro-82M.

  • You can pip install kokoro
  • 82M weights hosted on HF, auto-downloaded with huggingface_hub.hf_hub_download
  • Lightweight PyTorch modeling code split across two files
  • Uses misaki for G2P

Usage

The following can be run in a single cell on Google Colab.

# 1️⃣ Install kokoro
!pip install -q kokoro soundfile
# 2️⃣ Install espeak, used for out-of-dictionary fallback
!apt-get -qq -y install espeak-ng > /dev/null 2>&1
# You can skip espeak installation, but OOD words will be skipped unless you provide a fallback

# 3️⃣ Initalize a pipeline
from kokoro import KPipeline
from IPython.display import display, Audio
import soundfile as sf
# 🇺🇸 'a' => American English
# 🇬🇧 'b' => British English
pipeline = KPipeline(lang_code='a') # make sure lang_code matches voice

# The following text is for demonstration purposes only, unseen during training
text = '''
The sky above the port was the color of television, tuned to a dead channel.
"It's not like I'm using," Case heard someone say, as he shouldered his way through the crowd around the door of the Chat. "It's like my body's developed this massive drug deficiency."
It was a Sprawl voice and a Sprawl joke. The Chatsubo was a bar for professional expatriates; you could drink there for a week and never hear two words in Japanese.

These were to have an enormous impact, not only because they were associated with Constantine, but also because, as in so many other areas, the decisions taken by Constantine (or in his name) were to have great significance for centuries to come. One of the main issues was the shape that Christian churches were to take, since there was not, apparently, a tradition of monumental church buildings when Constantine decided to help the Christian church build a series of truly spectacular structures. The main form that these churches took was that of the basilica, a multipurpose rectangular structure, based ultimately on the earlier Greek stoa, which could be found in most of the great cities of the empire. Christianity, unlike classical polytheism, needed a large interior space for the celebration of its religious services, and the basilica aptly filled that need. We naturally do not know the degree to which the emperor was involved in the design of new churches, but it is tempting to connect this with the secular basilica that Constantine completed in the Roman forum (the so-called Basilica of Maxentius) and the one he probably built in Trier, in connection with his residence in the city at a time when he was still caesar.
'''

# 4️⃣ Generate, display, and save audio files in a loop.
generator = pipeline(
    text, voice='af_bella',
    speed=1, split_pattern=r'\n+'
)
for i, (gs, ps, audio) in enumerate(generator):
    print(i)  # i => index
    print(gs) # gs => graphemes/text
    print(ps) # ps => phonemes
    display(Audio(data=audio, rate=24000, autoplay=i==0))
    sf.write(f'{i}.wav', audio, 24000) # save each audio file

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kokoro-0.3.1.tar.gz (18.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kokoro-0.3.1-py3-none-any.whl (21.5 kB view details)

Uploaded Python 3

File details

Details for the file kokoro-0.3.1.tar.gz.

File metadata

  • Download URL: kokoro-0.3.1.tar.gz
  • Upload date:
  • Size: 18.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.5

File hashes

Hashes for kokoro-0.3.1.tar.gz
Algorithm Hash digest
SHA256 4f564805d971e8eb6ebc78755a0c54adea7a1f6497022d78e1d4b2ef72362499
MD5 4a7cb3a043a1fe38bd38481855905487
BLAKE2b-256 8697e7e92f4da82b59395978e68ff703f4de4bfb0433e9e883ea57c27b4cbebf

See more details on using hashes here.

File details

Details for the file kokoro-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: kokoro-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 21.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.5

File hashes

Hashes for kokoro-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 60a427dc79aef045a8ac12c8f5a6c5a9f149e7c817fee86ada369915a65d1e85
MD5 f32f3919f7ed4606786af35f67a87485
BLAKE2b-256 399d6da0fc8a8e0059ddac41e25b6b79c8a8f8b38511fe8ade78fbe5fa365306

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page