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

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

Open
flylinux opened this issue Sep 18, 2024 · 1 comment

Comments

@flylinux
Copy link

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 added a commit to willwade/tts-wrapper that referenced this issue Sep 29, 2024
@willwade
Copy link

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.

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

2 participants