k2-fsa / sherpa-onnx

Speech-to-text, text-to-speech, speaker diarization, and VAD using next-gen Kaldi with onnxruntime without Internet connection. Support embedded systems, Android, iOS, Raspberry Pi, RISC-V, x86_64 servers, websocket server/client, C/C++, Python, Kotlin, C#, Go, NodeJS, Java, Swift, Dart, JavaScript, Flutter, Object Pascal, Lazarus, Rust
https://k2-fsa.github.io/sherpa/onnx/index.html
Apache License 2.0
3.48k stars 410 forks source link

sherpa_onnx.OfflineTts(tts_config).generate callback parameters are incompatible with numpy 2.x. #1357

Open flylinux opened 1 month ago

flylinux commented 1 month ago

This issue causes data errors in the buffer when running the example at https://k2-fsa.github.io/sherpa/onnx/tts/pretrained_models/vits.html#generate-speech-with-python-script, resulting in no sound output.

Install the test environment

conda create -n sherpa-onnx python=3.12
conda activate sherpa-onnx
pip install sherpa-onnx sounddevice soundfile numpy

The following code returns no output in numpy 2.x, but normally in numpy 1.x:

import sherpa_onnx
import numpy as np

def generated_audio_callback(samples: np.ndarray, progress: float):
    print("输出接受的音频数据(与第一个接受到的相同则不输出)")
    for i in range(len(samples)):
        if samples[i] != samples[0]:
            print(f"recv msg: {i} {samples[i]}")
    return 1

tts_config = sherpa_onnx.OfflineTtsConfig(
    model=sherpa_onnx.OfflineTtsModelConfig(
        vits=sherpa_onnx.OfflineTtsVitsModelConfig(
            model="./vits-piper-en_US-amy-low/en_US-amy-low.onnx",
            lexicon="",
            data_dir="./vits-piper-en_US-amy-low/espeak-ng-data",
            dict_dir="",
            tokens="./vits-piper-en_US-amy-low/tokens.txt",
        ),
        provider="cpu",
        debug=True,
        num_threads=1,
    ),
    rule_fsts="",
    max_num_sentences=1,
)

tts = sherpa_onnx.OfflineTts(tts_config)
audio = tts.generate(
    "Today as always, men fall into two groups: slaves and free men.",
    sid=0,
    speed=1,
    callback=generated_audio_callback
)

Solution:

pip install numpy=1.26.4
willwade commented 1 month ago

You have no idea how much I could thank you so much for that. I wish I looked here earlier - ive been convinced my problem is something in my flaky code when in fact it was this. Hero.