Update readme with streaming example

This commit is contained in:
AbrahamSanders
2025-09-19 17:09:30 -04:00
parent 5c5da0dbe6
commit 89f4d917a0

View File

@@ -62,10 +62,12 @@ By default, when you first run the script, the model will be downloaded automati
### 2. Basic Usage ### 2. Basic Usage
```python ```python
import soundfile as sf import soundfile as sf
import numpy as np
from voxcpm import VoxCPM from voxcpm import VoxCPM
model = VoxCPM.from_pretrained("openbmb/VoxCPM-0.5B") model = VoxCPM.from_pretrained("openbmb/VoxCPM-0.5B")
# Non-streaming
wav = model.generate( wav = model.generate(
text="VoxCPM is an innovative end-to-end TTS model from ModelBest, designed to generate highly expressive speech.", text="VoxCPM is an innovative end-to-end TTS model from ModelBest, designed to generate highly expressive speech.",
prompt_wav_path=None, # optional: path to a prompt speech for voice cloning prompt_wav_path=None, # optional: path to a prompt speech for voice cloning
@@ -81,6 +83,18 @@ wav = model.generate(
sf.write("output.wav", wav, 16000) sf.write("output.wav", wav, 16000)
print("saved: output.wav") print("saved: output.wav")
# Streaming
chunks = []
for chunk in model.generate_streaming(
text = "Streaming text to speech is easy with VoxCPM!",
# supports same args as above
):
chunks.append(chunk)
wav = np.concatenate(chunks)
sf.write("output_streaming.wav", wav, 16000)
print("saved: output_streaming.wav")
``` ```
### 3. CLI Usage ### 3. CLI Usage