diff --git a/.gitignore b/.gitignore index e0fecee..5227375 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,30 @@ -# Files and directories created by pub. +# Miscellaneous +*.class +*.log +*.pyc +*.swp +.DS_Store +.atom/ +.buildlog/ +.history +.svn/ +migrate_working_dir/ + +# IntelliJ related +*.iml +*.ipr +*.iws +.idea/ + +# The .vscode folder contains launch configuration and tasks you configure in +# VS Code which you may wish to be included in version control, so this line +# is commented out by default. +#.vscode/ + +# Flutter/Dart/Pub related +# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock. +/pubspec.lock +**/doc/api/ .dart_tool/ .packages @@ -6,4 +32,4 @@ build/ ffmpeg/ railway/ -*.o \ No newline at end of file +*.o diff --git a/.gitmodules b/.gitmodules index dde6afd..ce1f056 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,3 @@ -[submodule "whisper.cpp"] - path = whisper.cpp - url = https://github.com/ggerganov/whisper.cpp.git -[submodule "native_lib/whisper.cpp"] - path = native_lib/whisper.cpp +[submodule "src/whisper.cpp"] + path = src/whisper.cpp url = https://github.com/ggerganov/whisper.cpp.git diff --git a/.metadata b/.metadata new file mode 100644 index 0000000..4cbacfe --- /dev/null +++ b/.metadata @@ -0,0 +1,42 @@ +# This file tracks properties of this Flutter project. +# Used by Flutter tool to assess capabilities and perform upgrades etc. +# +# This file should be version controlled. + +version: + revision: 135454af32477f815a7525073027a3ff9eff1bfd + channel: stable + +project_type: plugin_ffi + +# Tracks metadata for the flutter migrate command +migration: + platforms: + - platform: root + create_revision: 135454af32477f815a7525073027a3ff9eff1bfd + base_revision: 135454af32477f815a7525073027a3ff9eff1bfd + - platform: android + create_revision: 135454af32477f815a7525073027a3ff9eff1bfd + base_revision: 135454af32477f815a7525073027a3ff9eff1bfd + - platform: ios + create_revision: 135454af32477f815a7525073027a3ff9eff1bfd + base_revision: 135454af32477f815a7525073027a3ff9eff1bfd + - platform: linux + create_revision: 135454af32477f815a7525073027a3ff9eff1bfd + base_revision: 135454af32477f815a7525073027a3ff9eff1bfd + - platform: macos + create_revision: 135454af32477f815a7525073027a3ff9eff1bfd + base_revision: 135454af32477f815a7525073027a3ff9eff1bfd + - platform: windows + create_revision: 135454af32477f815a7525073027a3ff9eff1bfd + base_revision: 135454af32477f815a7525073027a3ff9eff1bfd + + # User provided section + + # List of Local paths (relative to this file) that should be + # ignored by the migrate tool. + # + # Files that are not part of the templates will be ignored by default. + unmanaged_files: + - 'lib/main.dart' + - 'ios/Runner.xcodeproj/project.pbxproj' diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..d41096c --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,30 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "example", + "cwd": "example", + "program": "lib/main.dart", + "request": "launch", + "type": "dart" + }, + { + "name": "example (profile mode)", + "cwd": "example", + "request": "launch", + "type": "dart", + "flutterMode": "profile" + }, + { + "name": "example (release mode)", + "cwd": "example", + "program": "lib/main.dart", + "request": "launch", + "type": "dart", + "flutterMode": "release" + } + ] +} diff --git a/CHANGELOG.md b/CHANGELOG.md index 2539978..80012aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,13 @@ +## 0.0.3 + +- support additional platforms + ## 0.0.2 + - support all audio with auto convert but need ffmpeg ## 0.0.1 + - now support all audio format but need convert ## 0.0.0 diff --git a/README.md b/README.md index 0957d7e..fcbca04 100644 --- a/README.md +++ b/README.md @@ -1,73 +1,57 @@ # Whisper -Whisper library speech to text offline, +Whisper library speech to text offline, ## Refrence + 1. [Whisper-Official](https://github.com/openai/whisper) 2. [Whisper.cpp](https://github.com/ggerganov/whisper.cpp) -> this library is not in maintenance, just for example, if you want to transcribe audio to text please use [galaxeus_ai](https://github.com/galaxeus/galaxeus_ai) - ## Screenshot [![Screenshot from 2022-10-24 17-28-26](https://user-images.githubusercontent.com/82513502/197506276-acd71547-5062-47c0-908c-95d3ed00b092.png)](https://www.youtube.com/watch?v=qQWPE3EvOS0) - - ## Install ```bash dart pub add whisper_dart ``` -## Compile library - -1. for linux -```bash -git clone --recursive https://github.com/azkadev/whisper_dart.git -cd whisper_dart -cd native_lib -make -sudo make install -``` - -2. for android -```bash -git clone --recursive https://github.com/azkadev/whisper_dart.git -cd whisper_dart -cd native_lib -make -make compile.android -``` - ## Tested on -I only have this device, so sorry I can't test other devices + 1. OS: Ubuntu 20.4 - CPU: Amd Ryzen 5500u + CPU: AMD Ryzen 5500u Ram: 8gb -2. Os: Android 11 +2. OS: Windows 11 Pro 22H2 (22621.1105) + CPU: AMD Ryzen 3600 + Ram: 16gb +3. OS: Android 11 CPU: Snapdragon 665 Ram: 3gb +4. OS: Android 13 + CPU: Snapdragon 730 + Ram: 4gb ## example -example dengan auto convert dari semua jenis audio ke wav whisper, `ffmpeg` harus terinstall + +auto convert a given audio to a proper wav accepted by whisper, `ffmpeg` must be installed + ```dart -// ignore_for_file: non_constant_identifier_names import 'package:galaxeus_lib/galaxeus_lib.dart'; import 'package:universal_io/io.dart'; import 'package:whisper_dart/whisper_dart.dart'; import 'package:ffmpeg_dart/ffmpeg_dart.dart'; void main(List arguments) { - DateTime time = DateTime.now(); - // print(res); + DateTime time = DateTime.now(); + Whisper whisper = Whisper( whisperLib: "whisper.cpp/whisper.so", ); try { var res = whisper.request( whisperRequest: WhisperRequest.fromWavFile( - /// auto convert to wav 16 + /// auto convert to wav 16 audio: WhisperAudioconvert.convert( audioInput: File("samples/audio.ogg"), audioOutput: File("samples/output.wav"), @@ -82,27 +66,20 @@ void main(List arguments) { } } ``` -result -```bash -{ - "@type":"transcribe", - "text":" Baby, aku pergi dulu ya, babai sayang. *muach*" -} -``` ## example 2 example convert audio to text without auto convert + ```dart -// ignore_for_file: non_constant_identifier_names import 'package:galaxeus_lib/galaxeus_lib.dart'; import 'package:universal_io/io.dart'; import 'package:whisper_dart/whisper_dart.dart'; import 'package:ffmpeg_dart/ffmpeg_dart.dart'; void main(List arguments) { - DateTime time = DateTime.now(); - // print(res); + DateTime time = DateTime.now(); + Whisper whisper = Whisper( whisperLib: "whisper.cpp/whisper.so", ); @@ -122,13 +99,14 @@ void main(List arguments) { ``` result + ```json { - "@type":"transcribe", - "text":" And so my fellow Americans, ask not what your country can do for you, ask what you can do for your country." + "@type": "transcribe", + "text": " And so my fellow Americans, ask not what your country can do for you, ask what you can do for your country." } ``` -Language Support +Language Support ![](https://github.com/openai/whisper/raw/main/language-breakdown.svg) diff --git a/analysis_options.yaml b/analysis_options.yaml index dee8927..5bcd91a 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -1,30 +1,3 @@ -# This file configures the static analysis results for your project (errors, -# warnings, and lints). -# -# This enables the 'recommended' set of lints from `package:lints`. -# This set helps identify many issues that may lead to problems when running -# or consuming Dart code, and enforces writing Dart using a single, idiomatic -# style and format. -# -# If you want a smaller set of lints you can change this to specify -# 'package:lints/core.yaml'. These are just the most critical lints -# (the recommended set includes the core lints). -# The core lints are also what is used by pub.dev for scoring packages. - -include: package:lints/recommended.yaml - -# Uncomment the following section to specify additional rules. - -# linter: -# rules: -# - camel_case_types - -# analyzer: -# exclude: -# - path/to/excluded/files/** - -# For more information about the core and recommended set of lints, see -# https://dart.dev/go/core-lints - -# For additional information about configuring this file, see +include: package:flutter_lints/flutter.yaml +# Additional information about this file can be found at # https://dart.dev/guides/language/analysis-options diff --git a/android/.gitignore b/android/.gitignore new file mode 100644 index 0000000..161bdcd --- /dev/null +++ b/android/.gitignore @@ -0,0 +1,9 @@ +*.iml +.gradle +/local.properties +/.idea/workspace.xml +/.idea/libraries +.DS_Store +/build +/captures +.cxx diff --git a/android/build.gradle b/android/build.gradle new file mode 100644 index 0000000..8d2b59c --- /dev/null +++ b/android/build.gradle @@ -0,0 +1,59 @@ +// The Android Gradle Plugin builds the native code with the Android NDK. + +group 'com.example.whisper_dart' +version '1.0' + +buildscript { + repositories { + google() + mavenCentral() + } + + dependencies { + // The Android Gradle Plugin knows how to build native code with the NDK. + classpath 'com.android.tools.build:gradle:7.1.2' + } +} + +rootProject.allprojects { + repositories { + google() + mavenCentral() + } +} + +apply plugin: 'com.android.library' + +android { + // Bumping the plugin compileSdkVersion requires all clients of this plugin + // to bump the version in their app. + compileSdkVersion 31 + + // Bumping the plugin ndkVersion requires all clients of this plugin to bump + // the version in their app and to download a newer version of the NDK. + ndkVersion "25.1.8937393" + + // Invoke the shared CMake build with the Android Gradle Plugin. + externalNativeBuild { + cmake { + path "../src/CMakeLists.txt" + + // The default CMake version for the Android Gradle Plugin is 3.10.2. + // https://developer.android.com/studio/projects/install-ndk#vanilla_cmake + // + // The Flutter tooling requires that developers have CMake 3.10 or later + // installed. You should not increase this version, as doing so will cause + // the plugin to fail to compile for some customers of the plugin. + // version "3.10.2" + } + } + + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + + defaultConfig { + minSdkVersion 16 + } +} diff --git a/android/settings.gradle b/android/settings.gradle new file mode 100644 index 0000000..c1d492f --- /dev/null +++ b/android/settings.gradle @@ -0,0 +1 @@ +rootProject.name = 'whisper_dart' diff --git a/android/src/main/AndroidManifest.xml b/android/src/main/AndroidManifest.xml new file mode 100644 index 0000000..5f55d3b --- /dev/null +++ b/android/src/main/AndroidManifest.xml @@ -0,0 +1,3 @@ + + diff --git a/bin/whisper_dart.dart b/bin/whisper_dart.dart index f8fce3b..879bf52 100644 --- a/bin/whisper_dart.dart +++ b/bin/whisper_dart.dart @@ -1,29 +1,24 @@ -// ignore_for_file: non_constant_identifier_names +// ignore_for_file: non_constant_identifier_names, avoid_print + +import 'dart:io'; -import 'package:galaxeus_lib/galaxeus_lib.dart'; -import 'package:universal_io/io.dart'; import 'package:whisper_dart/whisper_dart.dart'; -import 'package:ffmpeg_dart/ffmpeg_dart.dart'; void main(List arguments) { + Directory current = Directory.current; DateTime time = DateTime.now(); - // print(res); - Whisper whisper = Whisper( - whisperLib: "native_lib/whisper_dart.so", - ); + + Whisper whisper = Whisper(); try { var res = whisper.request( - whisperRequest: WhisperRequest.fromWavFile( - // audio: WhisperAudioconvert.convert( - // audioInput: File("/home/hexaminate/Documents/HEXAMINATE/app/ai/whisper_dart/samples/audio.ogg"), - // audioOutput: File("/home/hexaminate/Documents/HEXAMINATE/app/ai/whisper_dart/samples/output.wav"), - // ), - audio: File("/home/hexaminate/Documents/HEXAMINATE/app/ai/whisper_dart/samples/output.wav"), - model: File("/home/hexaminate/Documents/HEXAMINATE/app/ai/whisper_dart/models/ggml-model-whisper-small.bin"), + request: WhisperRequest.fromWavFile( + audio: File("${current.path}/samples/your_sample.wav"), + // check it here: https://github.com/ggerganov/whisper.cpp/tree/master/models + model: File("${current.path}/models/your_model.bin"), ), ); - print(res.toString()); - print(convertToAgo(time.millisecondsSinceEpoch)); + print(res.text); + print(time.millisecondsSinceEpoch); } catch (e) { print(e); } diff --git a/example/.gitignore b/example/.gitignore index 24476c5..1f59a3d 100644 --- a/example/.gitignore +++ b/example/.gitignore @@ -9,6 +9,7 @@ .history .svn/ migrate_working_dir/ +models/ # IntelliJ related *.iml diff --git a/example/README.md b/example/README.md index 2b3fce4..626e236 100644 --- a/example/README.md +++ b/example/README.md @@ -1,6 +1,6 @@ -# example +# whisper_dart_example -A new Flutter project. +Demonstrates how to use the whisper_dart plugin. ## Getting Started diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle index f20bba3..f271ac8 100644 --- a/example/android/app/build.gradle +++ b/example/android/app/build.gradle @@ -27,7 +27,7 @@ apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" android { compileSdkVersion 33 - ndkVersion flutter.ndkVersion + ndkVersion "25.1.8937393" compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 @@ -40,14 +40,11 @@ android { sourceSets { main.java.srcDirs += 'src/main/kotlin' - main { - jniLibs.srcDirs = ['jniLibs'] - } } defaultConfig { // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). - applicationId "com.example.example" + applicationId "com.example.whisper_dart_example" // You can update the following values to match your application needs. // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration. minSdkVersion flutter.minSdkVersion @@ -63,6 +60,7 @@ android { signingConfig signingConfigs.debug } } + namespace 'com.example.whisper_dart_example' } flutter { diff --git a/example/android/app/src/debug/AndroidManifest.xml b/example/android/app/src/debug/AndroidManifest.xml index 45d523a..399f698 100644 --- a/example/android/app/src/debug/AndroidManifest.xml +++ b/example/android/app/src/debug/AndroidManifest.xml @@ -1,5 +1,4 @@ - + + android:name="io.flutter.embedding.android.NormalTheme" + android:resource="@style/NormalTheme" + /> diff --git a/example/android/app/src/main/kotlin/com/example/whisper_dart_example/MainActivity.kt b/example/android/app/src/main/kotlin/com/example/whisper_dart_example/MainActivity.kt new file mode 100644 index 0000000..baebc25 --- /dev/null +++ b/example/android/app/src/main/kotlin/com/example/whisper_dart_example/MainActivity.kt @@ -0,0 +1,6 @@ +package com.example.whisper_dart_example + +import io.flutter.embedding.android.FlutterActivity + +class MainActivity: FlutterActivity() { +} diff --git a/example/android/app/src/profile/AndroidManifest.xml b/example/android/app/src/profile/AndroidManifest.xml index 45d523a..399f698 100644 --- a/example/android/app/src/profile/AndroidManifest.xml +++ b/example/android/app/src/profile/AndroidManifest.xml @@ -1,5 +1,4 @@ - + %s] %s\n", to_timestamp(t0).c_str(), to_timestamp(t1).c_str(), text); + printf("[%s --> %s] %s\n", to_timestamp(t0).c_str(), to_timestamp(t1).c_str(), text); } } } @@ -259,7 +267,8 @@ extern "C" { json jsonBody; jsonBody["@type"] = "al"; - print(transcribe(jsonBody).dump()); + transcribe(jsonBody).dump(); + fprintf(stderr, "%s: Proccess finished.", __func__); return 0; } } \ No newline at end of file diff --git a/src/whisper.cpp b/src/whisper.cpp new file mode 160000 index 0000000..2bee265 --- /dev/null +++ b/src/whisper.cpp @@ -0,0 +1 @@ +Subproject commit 2bee2650c66497b8804e3c82426373703c6d97a1 diff --git a/windows/CMakeLists.txt b/windows/CMakeLists.txt new file mode 100644 index 0000000..07898a3 --- /dev/null +++ b/windows/CMakeLists.txt @@ -0,0 +1,24 @@ +# The Flutter tooling requires that developers have a version of Visual Studio +# installed that includes CMake 3.14 or later. You should not increase this +# version, as doing so will cause the plugin to fail to compile for some +# customers of the plugin. +cmake_minimum_required(VERSION 3.14) + +# Project-level configuration. +set(PROJECT_NAME "whisper_dart") +project(${PROJECT_NAME} LANGUAGES C CXX) + + +# Invoke the build for native code shared with the other target platforms. +# This can be changed to accomodate different builds. +add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/../src" "${CMAKE_CURRENT_BINARY_DIR}/shared") + +# List of absolute paths to libraries that should be bundled with the plugin. +# This list could contain prebuilt libraries, or libraries created by an +# external build triggered from this build file. +set(whisper_dart_bundled_libraries + # Defined in ../src/CMakeLists.txt. + # This can be changed to accomodate different builds. + $ + PARENT_SCOPE +)