Skip to content

Commit

Permalink
Update iOS and Android demos to include the latest streaming zipformer (
Browse files Browse the repository at this point in the history
  • Loading branch information
csukuangfj authored Jun 27, 2023
1 parent dab22c4 commit b2e0c4c
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 4 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.13 FATAL_ERROR)
project(sherpa-onnx)

set(SHERPA_ONNX_VERSION "1.4.5")
set(SHERPA_ONNX_VERSION "1.4.6")

# Disable warning about
#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ class MainActivity : AppCompatActivity() {
// Please change getModelConfig() to add new models
// See https://k2-fsa.github.io/sherpa/onnx/pretrained_models/index.html
// for a list of available models
val type = 0
val type = 3
println("Select model type ${type}")
val config = OnlineRecognizerConfig(
featConfig = getFeatureConfig(sampleRate = sampleRateInHz, featureDim = 80),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ data class OnlineTransducerModelConfig(
var decoder: String,
var joiner: String,
var tokens: String,
var numThreads: Int = 2,
var numThreads: Int = 1,
var debug: Boolean = false,
)

Expand Down Expand Up @@ -122,6 +122,9 @@ by following the code)
2 - csukuangfj/sherpa-onnx-lstm-en-2023-02-17 (English)
https://k2-fsa.github.io/sherpa/onnx/pretrained_models/lstm-transducer-models.html#csukuangfj-sherpa-onnx-lstm-en-2023-02-17-english
3 - pkufool/icefall-asr-zipformer-streaming-wenetspeech-20230615
https://huggingface.co/pkufool/icefall-asr-zipformer-streaming-wenetspeech-20230615
*/
fun getModelConfig(type: Int): OnlineTransducerModelConfig? {
when (type) {
Expand Down Expand Up @@ -153,6 +156,26 @@ fun getModelConfig(type: Int): OnlineTransducerModelConfig? {
tokens = "$modelDir/tokens.txt",
)
}

3 -> {
val modelDir = "icefall-asr-zipformer-streaming-wenetspeech-20230615"
return OnlineTransducerModelConfig(
encoder = "$modelDir/exp/encoder-epoch-12-avg-4-chunk-16-left-128.int8.onnx",
decoder = "$modelDir/exp/decoder-epoch-12-avg-4-chunk-16-left-128.onnx",
joiner = "$modelDir/exp/joiner-epoch-12-avg-4-chunk-16-left-128.onnx",
tokens = "$modelDir/data/lang_char/tokens.txt",
)
}

4 -> {
val modelDir = "icefall-asr-zipformer-streaming-wenetspeech-20230615"
return OnlineTransducerModelConfig(
encoder = "$modelDir/exp/encoder-epoch-12-avg-4-chunk-16-left-128.onnx",
decoder = "$modelDir/exp/decoder-epoch-12-avg-4-chunk-16-left-128.onnx",
joiner = "$modelDir/exp/joiner-epoch-12-avg-4-chunk-16-left-128.onnx",
tokens = "$modelDir/data/lang_char/tokens.txt",
)
}
}
return null;
}
Expand Down
1 change: 1 addition & 0 deletions build-android-arm64-v8a.sh
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ cmake -DCMAKE_TOOLCHAIN_FILE="$ANDROID_NDK/build/cmake/android.toolchain.cmake"
-DSHERPA_ONNX_ENABLE_CHECK=OFF \
-DSHERPA_ONNX_ENABLE_PORTAUDIO=OFF \
-DSHERPA_ONNX_ENABLE_JNI=ON \
-DSHERPA_ONNX_ENABLE_C_API=OFF \
-DCMAKE_INSTALL_PREFIX=./install \
-DANDROID_ABI="arm64-v8a" \
-DANDROID_PLATFORM=android-21 ..
Expand Down
1 change: 1 addition & 0 deletions build-android-armv7-eabi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ cmake -DCMAKE_TOOLCHAIN_FILE="$ANDROID_NDK/build/cmake/android.toolchain.cmake"
-DSHERPA_ONNX_ENABLE_CHECK=OFF \
-DSHERPA_ONNX_ENABLE_PORTAUDIO=OFF \
-DSHERPA_ONNX_ENABLE_JNI=ON \
-DSHERPA_ONNX_ENABLE_C_API=OFF \
-DCMAKE_INSTALL_PREFIX=./install \
-DANDROID_ABI="armeabi-v7a" -DANDROID_ARM_NEON=ON \
-DANDROID_PLATFORM=android-21 ..
Expand Down
45 changes: 45 additions & 0 deletions ios-swift/SherpaOnnx/SherpaOnnx/Model.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,51 @@ func getBilingualStreamZhEnZipformer20230220() -> SherpaOnnxOnlineTransducerMode
)
}

func getZhZipformer20230615() -> SherpaOnnxOnlineTransducerModelConfig {
let encoder = getResource("encoder-epoch-12-avg-4-chunk-16-left-128", "onnx")
let decoder = getResource("decoder-epoch-12-avg-4-chunk-16-left-128", "onnx")
let joiner = getResource("joiner-epoch-12-avg-4-chunk-16-left-128", "onnx")
let tokens = getResource("tokens", "txt")

return sherpaOnnxOnlineTransducerModelConfig(
encoder: encoder,
decoder: decoder,
joiner: joiner,
tokens: tokens,
numThreads: 2
)
}

func getZhZipformer20230615Int8() -> SherpaOnnxOnlineTransducerModelConfig {
let encoder = getResource("encoder-epoch-12-avg-4-chunk-16-left-128.int8", "onnx")
let decoder = getResource("decoder-epoch-12-avg-4-chunk-16-left-128", "onnx")
let joiner = getResource("joiner-epoch-12-avg-4-chunk-16-left-128", "onnx")
let tokens = getResource("tokens", "txt")

return sherpaOnnxOnlineTransducerModelConfig(
encoder: encoder,
decoder: decoder,
joiner: joiner,
tokens: tokens,
numThreads: 2
)
}

func getEnZipformer20230626() -> SherpaOnnxOnlineTransducerModelConfig {
let encoder = getResource("encoder-epoch-99-avg-1-chunk-16-left-128", "onnx")
let decoder = getResource("decoder-epoch-99-avg-1-chunk-16-left-128", "onnx")
let joiner = getResource("joiner-epoch-99-avg-1-chunk-16-left-128", "onnx")
let tokens = getResource("tokens", "txt")

return sherpaOnnxOnlineTransducerModelConfig(
encoder: encoder,
decoder: decoder,
joiner: joiner,
tokens: tokens,
numThreads: 2
)
}

/// Please refer to
/// https://k2-fsa.github.io/sherpa/onnx/pretrained_models/index.html
/// to add more models if you need
4 changes: 3 additions & 1 deletion ios-swift/SherpaOnnx/SherpaOnnx/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ class ViewController: UIViewController {
// You can also modify Model.swift to add new pre-trained models from
// https://k2-fsa.github.io/sherpa/ncnn/pretrained_models/index.html

let modelConfig = getBilingualStreamZhEnZipformer20230220()
// let modelConfig = getBilingualStreamZhEnZipformer20230220()
// let modelConfig = getZhZipformer20230615()
let modelConfig = getEnZipformer20230626()

let featConfig = sherpaOnnxFeatureConfig(
sampleRate: 16000,
Expand Down

0 comments on commit b2e0c4c

Please sign in to comment.