Skip to content

Commit

Permalink
feat(example): use base model
Browse files Browse the repository at this point in the history
  • Loading branch information
jhen0409 committed Dec 15, 2023
1 parent 8204827 commit 8d5c325
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 20 deletions.
13 changes: 8 additions & 5 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -161,15 +161,15 @@ 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))
} else {
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: () => {},
Expand All @@ -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))
Expand All @@ -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: () => {},
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions example/src/context-opts.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
22 changes: 11 additions & 11 deletions scripts/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

0 comments on commit 8d5c325

Please sign in to comment.