Skip to content

Commit

Permalink
Fix CI tests for Python and JNI. (#554)
Browse files Browse the repository at this point in the history
  • Loading branch information
csukuangfj authored Jan 27, 2024
1 parent 7ae73e7 commit 44efff4
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 20 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/test-pip-install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ jobs:
shell: bash
run: |
pip install --verbose sherpa-onnx
# python3 -m pip install --verbose .
- name: Test sherp-onnx
- name: Test sherpa-onnx
shell: bash
run: |
python3 -c "import sherpa_onnx; print(sherpa_onnx.__file__)"
Expand All @@ -68,8 +69,8 @@ jobs:
export PATH=/c/hostedtoolcache/windows/Python/3.10.11/x64/bin:$PATH
export PATH=/c/hostedtoolcache/windows/Python/3.11.7/x64/bin:$PATH
sherpa-onnx --help
sherpa-onnx-keyword-spotter --help
sherpa-onnx-offline --help
sherpa-onnx-offline-tts --help
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ package com.k2fsa.sherpa.onnx

import android.content.res.AssetManager
import android.util.Log
import com.k2fsa.sherpa.onnx.speaker.identification.TAG


private val TAG = "sherpa-onnx"
data class SpeakerEmbeddingExtractorConfig(
val model: String,
var numThreads: Int = 1,
Expand Down
10 changes: 10 additions & 0 deletions kotlin-api-examples/faked-log.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package android.util

class Log {
companion object {
fun i(tag: String, msg: String) {
println("$tag, $msg")
}
}
}

2 changes: 1 addition & 1 deletion kotlin-api-examples/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ if [ ! -f ./vits-piper-en_US-amy-low/en_US-amy-low.onnx ]; then
rm vits-piper-en_US-amy-low.tar.bz2
fi

kotlinc-jvm -include-runtime -d main.jar Main.kt WaveReader.kt SherpaOnnx.kt faked-asset-manager.kt Tts.kt Speaker.kt
kotlinc-jvm -include-runtime -d main.jar Main.kt WaveReader.kt SherpaOnnx.kt faked-asset-manager.kt Tts.kt Speaker.kt faked-log.kt

ls -lh main.jar

Expand Down
8 changes: 0 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,6 @@ def get_package_version():
with open("sherpa-onnx/python/sherpa_onnx/__init__.py", "a") as f:
f.write(f"__version__ = '{get_package_version()}'\n")

install_requires = [
"numpy",
"sentencepiece==0.1.96; python_version < '3.11'",
"sentencepiece; python_version >= '3.11'",
"click>=7.1.1",
]


def get_binaries_to_install():
bin_dir = Path("build") / "sherpa_onnx" / "bin"
Expand Down Expand Up @@ -91,7 +84,6 @@ def get_binaries_to_install():
setuptools.setup(
name=package_name,
python_requires=">=3.6",
install_requires=install_requires,
version=get_package_version(),
author="The sherpa-onnx development team",
author_email="[email protected]",
Expand Down
9 changes: 8 additions & 1 deletion sherpa-onnx/python/sherpa_onnx/cli.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
# Copyright (c) 2023 Xiaomi Corporation

import logging
import click
try:
import click
except ImportError:
print('Please run')
print(' pip install click')
print('before you continue')
raise

from pathlib import Path
from sherpa_onnx import text2token

Expand Down
23 changes: 17 additions & 6 deletions sherpa-onnx/python/sherpa_onnx/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@
from pathlib import Path
from typing import List, Optional, Union

import sentencepiece as spm

from pypinyin import pinyin
from pypinyin.contrib.tone_convert import to_initials, to_finals_tone


def text2token(
texts: List[str],
tokens: str,
Expand Down Expand Up @@ -38,6 +32,23 @@ def text2token(
Return the encoded texts, it is a list of a list of token ids if output_ids
is True, or it is a list of list of tokens.
"""
try:
import sentencepiece as spm
except ImportError:
print('Please run')
print(' pip install sentencepiece')
print('before you continue')
raise

try:
from pypinyin import pinyin
from pypinyin.contrib.tone_convert import to_initials, to_finals_tone
except ImportError:
print('Please run')
print(' pip install pypinyin')
print('before you continue')
raise

assert Path(tokens).is_file(), f"File not exists, {tokens}"
tokens_table = {}
with open(tokens, "r", encoding="utf-8") as f:
Expand Down

0 comments on commit 44efff4

Please sign in to comment.