Flutter Whisper.cpp allows offline/on device - fast and accurate automatic speech recognition (ASR) using OpenAI's Whisper ASR model. Built on top of ggerganov's Whisper.cpp, the app uses flutter_rust_bridge to bind Flutter to Rust via FFI, and whisper-rs for Rust C bindings to Whisper.cpp. The app also utilizes the Record Dart library for recording .m4a in iOS which is then converted to a .wav file.
Click here to see my talk at Fluttercon 2023 on using Rust with Flutter
Tested with Flutter version 3.16.0 and Rust version 1.74.0
Runs on:
- iOS (17.0.3 and XCode 15.0)
- Android
- Mac OS (Sonoma 14.0 and XCode 15.0)
- Linux
- Windows
The example below took < 1 second to process the audio on an iPhone 12
IMG_0.2.MOV
The purpose of this app is to provide an example of performing automatic speech recognition using OpenAI's Whisper ASR model in Flutter. The benefits of this approach include:
- High-performance inference of Whisper ASR model.
- User-friendly interface for recording and transcribing speech.
To use the app, simply record speech by tapping the record button, and the app will automatically transcribe the speech using the Whisper ASR model. The results are displayed relatively quickly making it easy to see how accurate the transcription is.
The app has only been set up with iOS to start with and has been tested on an iPhone 12 and an iPad Air with a 2022 M1 chip. To install the app, follow these steps:
Note: due to using the ffmpeg library it's not currently working on the simulator, I will fix this but for the time being its recommended to use a real iOS device
- Clone the repository to your local machine.
- Install the necessary dependencies and libraries, i.e
flutter pub get
in the main directory andcargo build
in the./rs_whisper_gpt
directory. - Ensure the model is added to
/rs_whisper_gpt/ggml-base.en.bin
this is where XCode is currently looking for it. See Whisper.cpp for Installing/Downloading Models - it is set up withggml-base.en.bin
. - Run
flutter run -d {device}
- Download a new model (i.e ggml-tiny.en.bin) See Whisper.cpp for Installing/Downloading Models
- Add a reference to this file in XCode, make sure its in the Runner/Runner directory (important for the lookup in the Rust code, or change the path in the Rust code to reference this)
- Update the Rust code in
./rs_whisper_gpt/src/api.rs
to reference the name of the model - Run the flutter_rust_bridge_codegen command as described below to generate new bindings.
You can change the language of the model, you just need to set the language in the api call to the same code as the language you would like to use. You also need to make sure you use the correct model i.e ggml-tiny.bin instead of ggml-base.en.bin. See OpenAI Whisper for more details.
You will need to run the command
flutter_rust_bridge_codegen --rust-input rs_whisper_gpt/src/api.rs --dart-output lib/bridge_generated.dart -c ios/Runner/bridge_generated.h -e macos/Runner/
Check out the flutter_rust_bridge User Guide for more information
As per other examples in Whisper.cpp, the app has been optimized for performance by adding -O3 -DNDEBUG to Other C Flags. However, it is not recommended for production or real-world scenarios.