{"id":32273472,"url":"https://github.com/caldarie/flutter_tflite_audio","last_synced_at":"2026-02-21T08:02:19.392Z","repository":{"id":44174626,"uuid":"254627250","full_name":"Caldarie/flutter_tflite_audio","owner":"Caldarie","description":"Audio classification Tflite package for flutter (iOS \u0026 Android). Can support Google Teachable Machine models","archived":false,"fork":false,"pushed_at":"2024-01-25T08:20:33.000Z","size":13395,"stargazers_count":61,"open_issues_count":26,"forks_count":23,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-01-25T09:31:43.905Z","etag":null,"topics":["android","audio-classification","flutter","google-teachable-machine","ios","tflite"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Caldarie.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-04-10T12:18:40.000Z","updated_at":"2024-01-15T08:52:54.000Z","dependencies_parsed_at":"2023-01-22T14:45:49.553Z","dependency_job_id":null,"html_url":"https://github.com/Caldarie/flutter_tflite_audio","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/Caldarie/flutter_tflite_audio","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Caldarie%2Fflutter_tflite_audio","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Caldarie%2Fflutter_tflite_audio/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Caldarie%2Fflutter_tflite_audio/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Caldarie%2Fflutter_tflite_audio/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Caldarie","download_url":"https://codeload.github.com/Caldarie/flutter_tflite_audio/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Caldarie%2Fflutter_tflite_audio/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29676981,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-21T06:23:40.028Z","status":"ssl_error","status_checked_at":"2026-02-21T06:23:39.222Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","audio-classification","flutter","google-teachable-machine","ios","tflite"],"created_at":"2025-10-22T23:21:51.535Z","updated_at":"2026-02-21T08:02:19.387Z","avatar_url":"https://github.com/Caldarie.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TFlite Audio Plugin for Flutter\n\n[![pub package](https://img.shields.io/pub/v/tflite_audio.svg?label=version\u0026color=blue)](https://pub.dev/packages/tflite_audio)\n[![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/MIT)\n[![style: effective dart](https://img.shields.io/badge/style-effective_dart-40c4ff.svg)](https://pub.dev/packages/effective_dart)\n\n\u003cbr\u003e\n\nAudio classification Tflite package for flutter (iOS \u0026 Android). Can also support Google Teachable Machine models. \n\nIf you are a complete newbie to audio classification, you can read the tutorial [here](https://carolinamalbuquerque.medium.com/audio-recognition-using-tensorflow-lite-in-flutter-application-8a4ad39964ae). Credit to [Carolina](https://github.com/cmalbuquerque) for writing a comprehensive article.\n\nTo keep this project alive, consider giving a star or a like. Pull requests or bug reports are also welcome.\n\n\u003cbr\u003e\n\nRecording            |  Inference result\n:-------------------------:|:-------------------------:\n![](https://github.com/Caldarie/flutter_tflite_audio/blob/master/pictures/finish.png) | ![](https://github.com/Caldarie/flutter_tflite_audio/blob/master/pictures/start.png) \n\n\u003cbr\u003e\n\n## Table of Contents\n\n * [About this plugin](#about-this-plugin)\n * [Known Issues/Commonly asked questions](#known-issuescommonly-asked-questions)\n * [Please read if you are using Google's Teachable Machine. Otherwise skip.](#please-read-if-you-are-using-googles-teachable-machine-otherwise-skip)\n * [How to add tflite model and label to flutter](#how-to-add-tflite-model-and-label-to-flutter)\n * [How to use this plugin](#how-to-use-this-plugin)\n * [Rough guide on parameters](#rough-guide-on-the-parameters)\n * [Android Installation \u0026 Permissions](#android-installation--permissions)\n * [iOS Installation \u0026 Permissions](#ios-installation--permissions)\n * [References](#references)\n \n\u003cbr\u003e\n\n## About This Plugin\n\n### The plugin has several features:\n\n1. Audio recognition for stored audio files. (Only mono wav files for now)\n\n2. Audio recognition for recordings. \n\n3. Tunable parameters for recording/inferences\n   *  Please look a the [parameters](#rough-guide-on-the-parameters) below for more information.\n\n4. Automatically reshape/transpose audio inputs.\n\n\u003cbr\u003e\n\n### This plugin can support several model types:\n\n1. Google Teachable Machine (Raw audio input)\n\n   * For beginners with little to no machine learning knowledge. You can read can read the tutorial [here](https://carolinamalbuquerque.medium.com/audio-recognition-using-tensorflow-lite-in-flutter-application-8a4ad39964ae) if you are a newbie.\n   * Training can be done [here](https://teachablemachine.withgoogle.com/train/audio) \n\n2. Raw audio input. \n\n   * Can recognize the following inputs: float32[audioLength, 1] or float32[1, audioLength]\n   * For more information on how to train your own model, take a look [here](https://github.com/tensorflow/examples/tree/master/lite/examples/speech_commands/ml).\n\n3. Decoded wav input. \n\n   * Supports two inputs: float32[audioLength, 1] and int32[1]\n   * For more information on how to train your own model. Take a look [here](https://github.com/tensorflow/docs/blob/master/site/en/r1/tutorials/sequences/audio_recognition.md)\n   * To train a decoded wave with MFCC, take a look [here](https://github.com/tensorflow/tensorflow/tree/r1.15/tensorflow/examples/speech_commands)\n\n4. **(Experimental feature)**  Spectogram, melspectrogram, and MFCC inputs. \n\n   * Please note that this feature is experimental, and results may not be accurate compared to raw audio / decoded wav.\n   * Spectrogram model can be trained here [tutorial](https://www.tensorflow.org/tutorials/audio/simple_audio). \n\n5. **(Currently worked on feature)** Multiple input and outputs.\n\n\u003cbr\u003e\n\n## Known Issues/Commonly asked questions\n\n1. **How to adjust the recording length/time**\n\n   There are two ways to reduce adjust recording length/time:\n\n   * You can increase the recording time by adjusting the bufferSize to a lower value. \n  \n   * You can also increase recording time by lowering the sample rate.     \n  \n   **Note:** That stretching the value too low will cause problems with model accuracy. In that case, you may want to consider lowering your sample rate as well. Likewise, a very low sample rate can also cause problems with accuracy. It is your job to find the sweetspot for both values.\n\n2. **How to reduce false positives in my model**\n\n   To reduce false positives, you may want to adjust the default values of `detectionThreshold=0.3` and `averageWindowDuration=1000` to a higher value. A good value for both respectively are `0.7`  and `1500`. For more details about these parameters, please visit this [section](#rough-guide-on-the-parameters).\n\n3. **I am getting build errors on iOS**\n\n   There are several ways to fix this:\n\n   * Some have reported to fix this issue by replacing the following line:\n\n     ```ruby\n     target 'Runner' do\n       use_frameworks! \n       use_modular_headers!\n       #pod 'TensorFlowLiteSelectTfOps' #Old line\n       pod'TensorFlowLiteSelectTfOps','~\u003e 2.6.0' #New line\n\n       flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))\n     end\n     ```\n\n   * Others have fixed this issue building the app without the line: `pod 'TensorFlowLiteSelectTfOps`. Then rebuilding the app by re-adding the line again.\n\n   * Remember to run the following below:\n   \n   ```\n     1. cd into iOS folder\n\n     2. Run `flutter pub get` on terminal\n\n     3. Run `pod install` on terminal\n\n     4. Run `flutter clean` on terminal\n\n     5. Run `flutter run` on terminal. All done!\n   ```\n\n4. **I am getting TensorFlow Lite Error on iOS. -  Regular TensorFlow ops are not supported by this interpreter. Make sure you apply/link the Flex delegate before inference** \n\n   *  Please make sure that you have enabled ops-select on your [podfile - step 4 \u0026 Xcode - step 5](#ios-if-you-are-using-googles-teachable-machine-model-otherwise-skip) and [build gradle - step 3](#android-if-you-are-using-googles-teachable-machine-otherwise-skip)\n\n   * If you tried above, please run the example on a device (not emulator). If you still recieved this error, its very likely that theres an issue with cocoapod or Xcode configuration. Please check the [issue #7](https://github.com/Caldarie/flutter_tflite_audio/issues/7)\n\n   * If you recieved this error from your custom model (not GTM), its likely that you're using unsupported tensorflow operators for tflite, as found in [issue #5](https://github.com/Caldarie/flutter_tflite_audio/issues/5#issuecomment-789260402). For more details on which operators are supported, look at the official documentation [here](https://www.tensorflow.org/lite/guide/ops_compatibility)\n\n   * Take a looking at issue number 3 if none of the above works.  \n\n5. **(iOS) App crashes when running Google's Teachable Machine model** \n\n   Please run your simulation on actual iOS device. Running your device on M1 macs should also be ok.\n  \n   As of this moment, there's [limited support](https://github.com/tensorflow/tensorflow/issues/44997#issuecomment-734001671) for x86_64 architectures from the Tensorflow Lite select-ops framework. If you absolutely need to run it on an emulator, you can consider building the select ops framework yourself. Instructions can be found [here](https://www.tensorflow.org/lite/guide/ops_select#ios)\n\n6. **(Android) Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0xfffffff4 in tid 5403** \n\n   It seems like the latest tflite package for android is causing this issue. Until this issue is fixed, please run this package on an actual Android Device. \n\n\u003cbr\u003e\n\n## Please Read If You Are Using Google's Teachable Machine. (Otherwise Skip)\n\n\u003cbr\u003e\n\n**BE AWARE:** Google's Teachable Machine requires [select tensorflow operators](https://www.tensorflow.org/lite/guide/ops_select#using_bazel_xcode) to work. This feature is experimental and will cause the following issues:\n\n1. Increase the overall size of your app. If this is unnacceptable for you, it's recommended that you build your own custom model. Tutorials can be found in the [About this plugin section](#about-this-plugin)\n\n2. Emulators for iOS do not work due to limited support for x86_64 architectures. You need to run your simulation on an actual device. Issue can be found [here](https://github.com/tensorflow/tensorflow/issues/44997)\n  \n3. You will need to manually implement ops-select on your [podfile - step 4 \u0026 Xcode - step 5](#note-skip-below-if-your-are-not-using-google-teachable-machine-ios) and [build gradle - step 3](#note-skip-below-if-your-are-not-using-google-teachable-machine-android)\n\n\u003cbr\u003e\n\n## How to add tflite model and label to flutter:\n\n\u003cbr\u003e\n\n1. Create an assets folder and then place your custom tflite model and labels inside. \n\n![](https://github.com/Caldarie/flutter_tflite_audio/blob/master/pictures/model-label-asset.png)\n\n2. In pubsec.yaml, link your tflite model and label under 'assets'. For example:\n\n```\n  assets:\n    - assets/decoded_wav_model.tflite\n    - assets/decoded_wav_label.txt\n\n```\n\n\u003cbr\u003e\n\n## How to use this plugin\n\n\u003cbr\u003e\n\nPlease look at the [example](https://github.com/Caldarie/flutter_tflite_audio/tree/master/example) on how to implement these futures.\n\n\n1. To add the package in pubspec.yaml, open your terminal and run this line in your flutter project:\n\n   ```\n   flutter pub add tflite_audio\n   ```\n\n2. Import the plugin. For example:\n\n   ```\n   import 'package:tflite_audio/tflite_audio.dart';\n   ```\n\n\n3. To load your model:\n\n\n   ```dart\n   //Example for decodedWav models\n    TfliteAudio.loadModel(\n         model: 'assets/conv_actions_frozen.tflite',\n         label: 'assets/conv_actions_label.txt',\n         inputType: 'decodedWav');\n\n\n   //Example for Google's Teachable Machine models\n     TfliteAudio.loadModel(\n         model: 'assets/google_teach_machine_model.tflite',\n         label: 'assets/google_teach_machine_label.txt',\n         inputType: 'rawAudio');\n\n   //Example if you want to take advantage of all optional parameters from loadModel()\n     TfliteAudio.loadModel(\n       model: 'assets/conv_actions_frozen.tflite',\n       label: 'assets/conv_actions_label.txt',\n       inputType: 'decodedWav',\n       outputRawScores: false, \n       numThreads: 1,\n       isAsset: true,\n     );\n   ```\n\n\n4. To start and listen to the stream for inference results:\n\n    * Declare stream value\n      ```dart\n      Stream\u003cMap\u003cdynamic, dynamic\u003e\u003e recognitionStream;\n      ```\n\n    * If you want to use the recognition stream for recording:\n      ```dart\n      //Example values for Google's Teachable Machine models\n      recognitionStream = TfliteAudio.startAudioRecognition(\n        sampleRate: 44100,\n        bufferSize: 22016,\n        )\n\n      //Example values for decodedWav\n      recognitionStream = TfliteAudio.startAudioRecognition(\n        sampleRate: 16000,\n        bufferSize: 2000,\n        )\n        \n      //Example for advanced users who want to utilise all optional parameters from this package. \n      //Note the values are default.\n      recognitionStream = TfliteAudio.startAudioRecognition(\n        sampleRate: 44100,\n        bufferSize: 22016,\n        numOfInferences: 5,\n        audioLength = 44032,\n        detectionThreshold: 0.3, \n        averageWindowDuration = 1000,\n        minimumTimeBetweenSamples = 30,\n        suppressionTime = 1500,\n        )\n\n      ```\n\n    * If you want to use the recognition stream for stored audio files. \n\n       ```dart\n       //Example values for Google teachable models\n       recognitionStream = TfliteAudio.startFileRecognition(\n         sampleRate: 44100,\n         audioDirectory: \"assets/sampleAudio.wav\",\n         );\n\n      //Examples values for decodedWav\n       recognitionStream = TfliteAudio.startFileRecognition(\n         sampleRate: 16000,\n         audioDirectory: \"assets/sampleAudio.wav\",\n         );\n\n       //Example for advanced users who want to utilise all optional parameters from this package. \n       recognitionStream = TfliteAudio.startFileRecognition(\n         sampleRate: 44100,\n         audioDirectory: \"assets/sampleAudio.wav\",\n         audioLength: 44032,\n         detectionThreshold: 0.3,\n         averageWindowDuration: 1000,\n         minimumTimeBetweenSamples: 30,\n         suppressionTime: 1500,\n         );\n       ```\n\n    * Listen for results \n      ```dart\n      String result = '';\n      int inferenceTime = 0;\n\n      recognitionStream.listen((event){\n            result = event[\"inferenceTime\"];\n            inferenceTime = event[\"recognitionResult\"];\n            })\n          .onDone(\n             //Do something here when stream closes\n           );\n      ```\n\n5. To forcibly cancel recognition stream\n  \n   ```dart\n   TfliteAudio.stopAudioRecognition();\n   ```\n\n\u003c/br\u003e\n\n## Rough guide on the parameters\n  \n  * outputRawScores - Will output the result as an array in string format. For example `'[0.2, 0.6, 0.1, 0.1]'`\n\n  * numThreads -  Higher threads will reduce inferenceTime. However, will utilise the more cpu resource.\n\n  * isAsset - is your model, label or audio file in the asset file? If yes, set true. If the files are outside (such as external storage), set false.\n  \n  * numOfInferences - determines how many times you want to loop the recording and inference. For example:\n`numOfInference = 3` will repeat the recording three times, so recording length will be (1 to 2 seconds) x 3 = (3 to 6 seconds). Also the model will output the scores three times.\n\n  * sampleRate - A higher sample rate may improve accuracy for recordings. Recommened values are 16000, 22050, 44100\n\n  * audioLength - Default is 0 as the plugin will determine the length for you. You can manually adjust this if you wish to shorten or extend the number of audio samples.\n\n  * bufferSize - A lower value will lengthen the recording. Likewise, a higehr value will shorten the recording. Make sure this value is equal or below your recording length. \n    \n  * detectionThreshold - Will ignore any predictions where its probability does not exceed the detection threshold. Useful for situations where you pickup unwanted/unintentional sounds. Lower the value if your model's performance isn't doing too well.\n\n  * suppressionMs - If your detection triggers too early, the result may be poor or inaccurate. Adjust the values to avoid this situation.\n\n  * averageWindowDurationMs - Use to remove earlier results that are too old.\n\n  * minimumTimeBetweenSamples - Ignore any results that are coming in too frequently\n\n\u003cbr\u003e\n\n## Android Installation \u0026 Permissions\n\n1. Add the permissions below to your AndroidManifest. This could be found in `\u003cYourApp\u003e/android/app/src`. For example:\n\n   ```\n   \u003cuses-permission android:name=\"android.permission.RECORD_AUDIO\" /\u003e\n   \u003cuses-permission android:name=\"android.permission.WRITE_EXTERNAL_STORAGE\" /\u003e\n   ```\n\n2. Edit the following below to your build.gradle. This could be found in `\u003cYourApp\u003e/app/src/`. For example:\n\n   ```Gradle\n   aaptOptions {\n           noCompress 'tflite'\n   ```\n\n\u003cbr\u003e\n\n#### **NOTE:** Skip below if your are not using Google Teachable Machine (Android)\n\n\u003cbr\u003e\n\n\n1. Enable select-ops under dependencies in your build gradle.\n\n   ```Gradle\n   dependencies {\n       compile 'org.tensorflow:tensorflow-lite-select-tf-ops:+'\n   }\n   ```\n\n\u003cbr\u003e\n\n## iOS Installation \u0026 Permissions\n\n1. Add the following key to Info.plist for iOS. This could be found in `\u003cYourApp\u003e/ios/Runner`\n   ```\n   \u003ckey\u003eNSMicrophoneUsageDescription\u003c/key\u003e\n   \u003cstring\u003eRecord audio for playback\u003c/string\u003e\n   ```\n\n2. Change the deployment target to a minumum of 12.0 or higher. This could be done by:\n\n   * Open your project workspace on xcode. Project workspace can be found here: `\u003cYourApp\u003e/ios/Runner.xcworkspace`\n  \n   * Select the top level Runner on the left panel\n   \n   * Select the Runner under Project.\n  \n   * Under the info tab, change the iOS deployment target to a minimum of 12.0 or higher\n\n   ![](https://github.com/Caldarie/flutter_tflite_audio/blob/master/pictures/deployment-target.png)\n    \n3. Open your podfile (found here: `\u003cYourApp\u003e/ios/Podfile`) and change platform ios to a minimum 12 or higher. \n\n   ```ruby\n   platform :ios, '12.0'\n   ```\n\n\u003cbr\u003e\n\n#### **NOTE:** Skip below if your are not using Google Teachable Machine (iOS)\n\n\u003cbr\u003e\n\n\n1. In the same podfile, add `pod 'TensorFlowLiteSelectTfOps' under target.\n\n   ```ruby\n   target 'Runner' do\n     use_frameworks! \n     use_modular_headers!\n     pod'TensorFlowLiteSelectTfOps','~\u003e 2.6.0' #Add this line here\n\n     flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))\n   end\n   ```\n\n2. Force load Select Ops for Tensorflow. To do that:\n\n   * Open your project on xcode \n    \n   * click on runner under \"Targets\"\n  \n   * Click on \"Build settings\" tab\n\n   * Click on \"All\" tab\n\n   * Click on the empty space which is on the right side of \"Other Links Flag\"\n\n   * Add the following line: `-force_load $(SRCROOT)/Pods/TensorFlowLiteSelectTfOps/Frameworks/TensorFlowLiteSelectTfOps.framework/TensorFlowLiteSelectTfOps`\n\n   ![](https://github.com/Caldarie/flutter_tflite_audio/blob/master/pictures/tflite-select-ops-installation.png)\n\n\n3. Install the ops-select package to pod. To do this:\n\n     * cd into iOS folder\n\n     * Run `flutter pub get` on terminal\n\n     * Run `pod install` on terminal\n\n     * Run `flutter clean` on terminal\n\n     * Run `flutter run` on terminal. All done!\n    \n\u003cbr\u003e\n\n## References\n\nThis project wouldn't of been possible if it wasn't for the following:\n\n1. Project is based on:\n   * https://github.com/tensorflow/examples/tree/master/lite/examples/speech_commands\n2. Tflite \u0026 select ops:\n   * https://www.tensorflow.org/lite/guide/ops_select\n   * https://libraries.io/cocoapods/TensorFlowLiteSelectTfOps\n3. Spectogram libraries:\n   * https://github.com/Subtitle-Synchronizer/jlibrosa\n   * https://github.com/dhrebeniuk/RosaKit\n4. RxJava and RxSwift\n   * https://github.com/ReactiveX/RxAndroid\n   * https://github.com/ReactiveX/RxJava\n   * https://github.com/ReactiveX/RxSwift\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcaldarie%2Fflutter_tflite_audio","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcaldarie%2Fflutter_tflite_audio","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcaldarie%2Fflutter_tflite_audio/lists"}