Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kokoro TTS (Python) omits the word "specified" #24

Closed
Deep0Thinking opened this issue Jan 30, 2025 · 5 comments
Closed

Kokoro TTS (Python) omits the word "specified" #24

Deep0Thinking opened this issue Jan 30, 2025 · 5 comments

Comments

@Deep0Thinking
Copy link

Deep0Thinking commented Jan 30, 2025

Hi! I've noticed that Kokoro TTS Python library consistently skips the word "specified" in the generated audio (I only tested for voice='am_michael' and voice='af_bella'), yet the online demo at hexgrad/Kokoro-TTS pronounces it correctly.

  • Kokoro Version: 0.3.1
  • OS: Windows

My python code:

import os
import numpy as np
import soundfile as sf
from kokoro import KPipeline
from IPython.display import display, Audio

with open("script.txt", "r", encoding="utf-8") as f:
    text = f.read()

pipeline = KPipeline(lang_code='a')

generator = pipeline(
    text, 
    voice='am_michael',
    speed=1,
    split_pattern=r'\n+'
)

os.makedirs('output', exist_ok=True)
combined_audio = []

for i, (gs, ps, audio) in enumerate(generator):
    print(i, gs)
    display(Audio(data=audio, rate=24000, autoplay=(i == 0)))

    combined_audio.append(audio)

full_audio = np.concatenate(combined_audio)
sf.write('output/full.wav', full_audio, 24000)

script.txt:

These are being specified in the text.

In the specified field.

Could you please help investigate why the word "specified" is dropped by the Python version, but not in the Hugging Face demo? Thanks!

@hexgrad
Copy link
Owner

hexgrad commented Jan 30, 2025

@Deep0Thinking

  1. Check if you have installed espeak-ng by running espeak-ng --version on your command line.
  2. If you already had espeak-ng installed, follow RuntimeError: espeak not installed on your system bootphon/phonemizer#44 (comment) to make sure the espeak-ng path is known.
  3. If you have done both of those things and specified is still being skipped, please also provide the print output of print(i, gs, ps) in your next troubleshooting comment.

@Deep0Thinking
Copy link
Author

@hexgrad

It works, thanks a lot for the solution!

@UyCode
Copy link

UyCode commented Feb 12, 2025

@Deep0Thinking

  1. Check if you have installed espeak-ng by running espeak-ng --version on your command line.
  2. If you already had espeak-ng installed, follow RuntimeError: espeak not installed on your system bootphon/phonemizer#44 (comment) to make sure the espeak-ng path is known.
  3. If you have done both of those things and specified is still being skipped, please also provide the print output of print(i, gs, ps) in your next troubleshooting comment.

I do installed the espeak-ng and it is in the PATH

this is my code, and result:

from kokoro import KPipeline
import soundfile as sf
import os

os.environ["PHONEMIZER_ESPEAK_LIBRARY"] = 'C:\Program Files\eSpeak NG\libespeak-ng.dll'
os.environ["_SEPEAK_LIBRARY"] = 'C:\Program Files\eSpeak NG\libespeak-ng.dll'
os.environ["PHONEMIZER_ESPEAK_PATH"] = 'C:\Program Files\eSpeak NG\espeak-ng.exe'

pipeline = KPipeline(lang_code='a')

text = '''
This is a specified Microsoft corporation with Kokoro
'''

generator = pipeline(
    text, voice='af_sarah', # <= change voice here
    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

result:
0
This is a specified Microsoft corporation with Kokoro
ðˌɪs ɪz ɐ kˌɔɹpəɹˈAʃən wɪð

@hexgrad
Copy link
Owner

hexgrad commented Feb 12, 2025

@UyCode try the following:

from misaki import en, espeak
fallback = espeak.EspeakFallback(british=False)

@UyCode
Copy link

UyCode commented Feb 12, 2025

thank you for providing the help, it works

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants