Spaces:
Sleeping
Sleeping
File size: 900 Bytes
9acb9c3 9a88d9c 9acb9c3 9a88d9c 9acb9c3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
from kokoro import KPipeline
import soundfile as sf
import torch
# Initialize Kokoro pipeline
pipeline = KPipeline(lang_code='a')
# Text to convert to speech
text = '''
[Kokoro](/kˈOkəɹO/) is an open-weight TTS model with 82 million parameters. Despite its lightweight architecture, it delivers comparable quality to larger models while being significantly faster and more cost-efficient. With Apache-licensed weights, [Kokoro](/kˈOkəɹO/) can be deployed anywhere from production environments to personal projects.
'''
# Generate speech using Kokoro
generator = pipeline(text, voice='af_heart')
# Process and save the generated audio
for i, (gs, ps, audio) in enumerate(generator):
print(f"Segment {i}: gs={gs}, ps={ps}")
# Save each segment as a separate file
sf.write(f'{i}.wav', audio, 24000)
print(f"Saved segment {i} as {i}.wav")
print("Speech generation completed!")
|