From 8d5c325711ab9b3e8d84702bab0e5cac6287edf0 Mon Sep 17 00:00:00 2001 From: jhen Date: Fri, 15 Dec 2023 08:27:04 +0800 Subject: [PATCH] feat(example): use base model --- example/src/App.tsx | 13 ++++++++----- example/src/context-opts.ios.ts | 8 ++++---- scripts/bootstrap.sh | 22 +++++++++++----------- 3 files changed, 23 insertions(+), 20 deletions(-) diff --git a/example/src/App.tsx b/example/src/App.tsx index df09f8d..531034f 100644 --- a/example/src/App.tsx +++ b/example/src/App.tsx @@ -140,7 +140,7 @@ export default function App() { log('Initialize context...') const startTime = Date.now() const ctx = await initWhisper({ - filePath: require('../assets/ggml-tiny.en.bin'), + filePath: require('../assets/ggml-base.bin'), ...contextOpts, }) const endTime = Date.now() @@ -161,7 +161,7 @@ export default function App() { log('Released previous context') } await createDir(log) - const modelFilePath = `${fileDir}/ggml-tiny.en.bin` + const modelFilePath = `${fileDir}/ggml-base.bin` if (await RNFS.exists(modelFilePath)) { log('Model already exists:') log(filterPath(modelFilePath)) @@ -169,7 +169,7 @@ export default function App() { log('Start Download Model to:') log(filterPath(modelFilePath)) await RNFS.downloadFile({ - fromUrl: `${modelHost}/ggml-tiny.en.bin`, + fromUrl: `${modelHost}/ggml-base.bin`, toFile: modelFilePath, progressInterval: 1000, begin: () => {}, @@ -180,7 +180,7 @@ export default function App() { } // If you don't want to enable Core ML, you can remove this - const coremlModelFilePath = `${fileDir}/ggml-tiny.en-encoder.mlmodelc.zip` + const coremlModelFilePath = `${fileDir}/ggml-base-encoder.mlmodelc.zip` if ( Platform.OS === 'ios' && (await RNFS.exists(coremlModelFilePath)) @@ -191,7 +191,7 @@ export default function App() { log('Start Download Core ML Model to:') log(filterPath(coremlModelFilePath)) await RNFS.downloadFile({ - fromUrl: `${modelHost}/ggml-tiny.en-encoder.mlmodelc.zip`, + fromUrl: `${modelHost}/ggml-base-encoder.mlmodelc.zip`, toFile: coremlModelFilePath, progressInterval: 1000, begin: () => {}, @@ -279,7 +279,10 @@ export default function App() { await createDir(log) const { stop, subscribe } = await whisperContext.transcribeRealtime({ + maxLen: 1, language: 'en', + // Enable beam search (may be slower than greedy but more accurate) + // beamSize: 2, // Record duration in seconds realtimeAudioSec: 60, // Slice audio into 25 (or < 30) sec chunks for better performance diff --git a/example/src/context-opts.ios.ts b/example/src/context-opts.ios.ts index f0784b9..39a1057 100644 --- a/example/src/context-opts.ios.ts +++ b/example/src/context-opts.ios.ts @@ -6,11 +6,11 @@ export default { coreMLModelAsset: Platform.OS === 'ios' ? { - filename: 'ggml-tiny.en-encoder.mlmodelc', + filename: 'ggml-base-encoder.mlmodelc', assets: [ - require('../assets/ggml-tiny.en-encoder.mlmodelc/weights/weight.bin'), - require('../assets/ggml-tiny.en-encoder.mlmodelc/model.mil'), - require('../assets/ggml-tiny.en-encoder.mlmodelc/coremldata.bin'), + require('../assets/ggml-base-encoder.mlmodelc/weights/weight.bin'), + require('../assets/ggml-base-encoder.mlmodelc/model.mil'), + require('../assets/ggml-base-encoder.mlmodelc/coremldata.bin'), ], } : undefined, diff --git a/scripts/bootstrap.sh b/scripts/bootstrap.sh index db1add9..3d5c6fb 100755 --- a/scripts/bootstrap.sh +++ b/scripts/bootstrap.sh @@ -83,21 +83,21 @@ cd whisper.cpp/models # If CI env is `true`, use dummy model if [ "$CI" = "true" ]; then - cp for-tests-ggml-tiny.en.bin ggml-tiny.en.bin - echo "CI: Copied for-tests-ggml-tiny.en.bin to ggml-tiny.en.bin" + cp for-tests-ggml-base.bin ggml-base.bin + echo "CI: Copied for-tests-ggml-base.bin to ggml-base.bin" else - ./download-ggml-model.sh tiny.en + ./download-ggml-model.sh base fi # Copy to assets cp ../samples/jfk.wav ../../example/assets -cp ggml-tiny.en.bin ../../example/assets -echo "Copied ggml-tiny.en.bin to example/assets" +cp ggml-base.bin ../../example/assets +echo "Copied ggml-base.bin to example/assets" -# Check whisper.cpp/models/ggml-tiny.en-encoder.mlmodelc exist -if [ ! -d ./ggml-tiny.en-encoder.mlmodelc ]; then - URL=https://huggingface.co/ggerganov/whisper.cpp/resolve/main/ggml-tiny.en-encoder.mlmodelc.zip - FILE=ggml-tiny.en-encoder.mlmodelc.zip +# Check whisper.cpp/models/ggml-base-encoder.mlmodelc exist +if [ ! -d ./ggml-base-encoder.mlmodelc ]; then + URL=https://huggingface.co/ggerganov/whisper.cpp/resolve/main/ggml-base-encoder.mlmodelc.zip + FILE=ggml-base-encoder.mlmodelc.zip if [ -x "$(command -v wget)" ]; then wget --no-config --quiet --show-progress -O $FILE $URL @@ -112,6 +112,6 @@ if [ ! -d ./ggml-tiny.en-encoder.mlmodelc ]; then rm $FILE fi -if [ ! -d ../../example/assets/ggml-tiny.en-encoder.mlmodelc ]; then - cp -r ./ggml-tiny.en-encoder.mlmodelc ../../example/assets/ +if [ ! -d ../../example/assets/ggml-base-encoder.mlmodelc ]; then + cp -r ./ggml-base-encoder.mlmodelc ../../example/assets/ fi