Flutter demo for real-time speech recognition (#1042)
This commit is contained in:
74
scripts/flutter/build-macos-streaming-asr.sh.in
Executable file
74
scripts/flutter/build-macos-streaming-asr.sh.in
Executable file
@@ -0,0 +1,74 @@
|
||||
#!/usr/bin/env bash
|
||||
set -ex
|
||||
|
||||
log() {
|
||||
# This function is from espnet
|
||||
local fname=${BASH_SOURCE[1]##*/}
|
||||
echo -e "$(date '+%Y-%m-%d %H:%M:%S') (${fname}:${BASH_LINENO[0]}:${FUNCNAME[1]}) $*"
|
||||
}
|
||||
|
||||
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
|
||||
SHERPA_ONNX_DIR=$(cd $SCRIPT_DIR/../.. && pwd)
|
||||
log "SCRIPT_DIR: $SCRIPT_DIR"
|
||||
log "SHERPA_ONNX_DIR: $SHERPA_ONNX_DIR"
|
||||
|
||||
SHERPA_ONNX_VERSION=$(grep "SHERPA_ONNX_VERSION" $SHERPA_ONNX_DIR/CMakeLists.txt | cut -d " " -f 2 | cut -d '"' -f 2)
|
||||
log "SHERPA_ONNX_VERSION: $SHERPA_ONNX_VERSION"
|
||||
|
||||
if [ -z $arch ]; then
|
||||
arch=x86_64
|
||||
fi
|
||||
|
||||
log "arch: $arch"
|
||||
|
||||
{% for model in model_list %}
|
||||
pushd $SHERPA_ONNX_DIR/flutter-examples/streaming_asr/
|
||||
model_name={{ model.model_name }}
|
||||
lang={{ model.lang }}
|
||||
type={{ model.idx }}
|
||||
short_name={{ model.short_name }}
|
||||
|
||||
pushd assets
|
||||
|
||||
curl -SL -O https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/${model_name}.tar.bz2
|
||||
tar xvf ${model_name}.tar.bz2
|
||||
|
||||
{{ model.cmd }}
|
||||
|
||||
rm -rf *.tar.bz2
|
||||
ls -lh $model_name
|
||||
|
||||
popd
|
||||
|
||||
git checkout ./
|
||||
sed -i.bak "s| - assets/$| - assets/\n - assets/$model_name/|g" ./pubspec.yaml
|
||||
|
||||
sed -i.bak "s/final type = .*;$/final type = $type;/g" ./lib/streaming_asr.dart
|
||||
|
||||
{% if model.rule_fsts %}
|
||||
rule_fsts={{ model.rule_fsts }}
|
||||
sed -i.bak "s|ruleFsts: ''|ruleFsts: await copyAssetFile(\'assets/$rule_fsts\')|g" ./lib/streaming_asr.dart
|
||||
{% endif %}
|
||||
|
||||
git diff .
|
||||
|
||||
flutter pub get
|
||||
|
||||
export FLUTTER_XCODE_ARCHS=$arch
|
||||
log "FLUTTER_XCODE_ARCHS: $FLUTTER_XCODE_ARCHS"
|
||||
|
||||
flutter build macos
|
||||
|
||||
pushd build/macos/Build/Products/Release/
|
||||
ls -lh
|
||||
|
||||
app=sherpa-onnx-$SHERPA_ONNX_VERSION-osx-$arch-asr-$lang-$short_name.app
|
||||
mv streaming_asr.app $app
|
||||
tar cjfv $app.tar.bz2 $app
|
||||
ls -lh
|
||||
mv $app.tar.bz2 $SHERPA_ONNX_DIR
|
||||
popd
|
||||
|
||||
popd
|
||||
|
||||
{% endfor %}
|
||||
Reference in New Issue
Block a user