diff --git a/.gitignore b/.gitignore index e372dbd..bf6d53a 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 @@ -7,7 +33,10 @@ build/ ffmpeg/ railway/ *.o +<<<<<<< HEAD *.so *.wav whisper_api/ -whisper_api_railway/ \ No newline at end of file +whisper_api_railway/ +======= +>>>>>>> e00b55753994ebd5a0ec17fcc2e129383927717a diff --git a/.gitmodules b/.gitmodules index 770172a..ded2543 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,4 +1,9 @@ +<<<<<<< HEAD [submodule "native_lib/whisper.cpp"] path = native_lib/whisper.cpp +======= +[submodule "src/whisper.cpp"] + path = src/whisper.cpp +>>>>>>> e00b55753994ebd5a0ec17fcc2e129383927717a 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/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 new file mode 100644 index 0000000..879bf52 --- /dev/null +++ b/bin/whisper_dart.dart @@ -0,0 +1,25 @@ +// ignore_for_file: non_constant_identifier_names, avoid_print + +import 'dart:io'; + +import 'package:whisper_dart/whisper_dart.dart'; + +void main(List arguments) { + Directory current = Directory.current; + DateTime time = DateTime.now(); + + Whisper whisper = Whisper(); + try { + var res = whisper.request( + 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.text); + print(time.millisecondsSinceEpoch); + } catch (e) { + print(e); + } +} diff --git a/example/README.md b/example/README.md new file mode 100644 index 0000000..626e236 --- /dev/null +++ b/example/README.md @@ -0,0 +1,16 @@ +# whisper_dart_example + +Demonstrates how to use the whisper_dart plugin. + +## Getting Started + +This project is a starting point for a Flutter application. + +A few resources to get you started if this is your first Flutter project: + +- [Lab: Write your first Flutter app](https://docs.flutter.dev/get-started/codelab) +- [Cookbook: Useful Flutter samples](https://docs.flutter.dev/cookbook) + +For help getting started with Flutter development, view the +[online documentation](https://docs.flutter.dev/), which offers tutorials, +samples, guidance on mobile development, and a full API reference. diff --git a/example/test/widget_test.dart b/example/test/widget_test.dart new file mode 100644 index 0000000..a319734 --- /dev/null +++ b/example/test/widget_test.dart @@ -0,0 +1,30 @@ +// This is a basic Flutter widget test. +// +// To perform an interaction with a widget in your test, use the WidgetTester +// utility in the flutter_test package. For example, you can send tap and scroll +// gestures. You can also use WidgetTester to find child widgets in the widget +// tree, read text, and verify that the values of widget properties are correct. + +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; + +import 'package:whisper_dart_example/main.dart'; + +void main() { + testWidgets('Counter increments smoke test', (WidgetTester tester) async { + // Build our app and trigger a frame. + await tester.pumpWidget(const MyApp()); + + // Verify that our counter starts at 0. + expect(find.text('0'), findsOneWidget); + expect(find.text('1'), findsNothing); + + // Tap the '+' icon and trigger a frame. + await tester.tap(find.byIcon(Icons.add)); + await tester.pump(); + + // Verify that our counter has incremented. + expect(find.text('0'), findsNothing); + expect(find.text('1'), findsOneWidget); + }); +} diff --git a/ios/Classes/whisper_dart.c b/ios/Classes/whisper_dart.c new file mode 100644 index 0000000..e7235d6 --- /dev/null +++ b/ios/Classes/whisper_dart.c @@ -0,0 +1,3 @@ +// Relative import to be able to reuse the C sources. +// See the comment in ../{projectName}}.podspec for more information. +#include "../../src/whisper_dart.c" diff --git a/ios/whisper_dart.podspec b/ios/whisper_dart.podspec new file mode 100644 index 0000000..d7a41a5 --- /dev/null +++ b/ios/whisper_dart.podspec @@ -0,0 +1,28 @@ +# +# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html. +# Run `pod lib lint whisper_dart.podspec` to validate before publishing. +# +Pod::Spec.new do |s| + s.name = 'whisper_dart' + s.version = '0.0.1' + s.summary = 'A new Flutter FFI plugin project.' + s.description = <<-DESC +A new Flutter FFI plugin project. + DESC + s.homepage = 'http://example.com' + s.license = { :file => '../LICENSE' } + s.author = { 'Your Company' => 'email@example.com' } + + # This will ensure the source files in Classes/ are included in the native + # builds of apps using this FFI plugin. Podspec does not support relative + # paths, so Classes contains a forwarder C file that relatively imports + # `../src/*` so that the C sources can be shared among all target platforms. + s.source = { :path => '.' } + s.source_files = 'Classes/**/*' + s.dependency 'Flutter' + s.platform = :ios, '9.0' + + # Flutter.framework does not contain a i386 slice. + s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES', 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'i386' } + s.swift_version = '5.0' +end diff --git a/lib/src/whisper_dart.dart b/lib/src/whisper_dart.dart new file mode 100644 index 0000000..0d48837 --- /dev/null +++ b/lib/src/whisper_dart.dart @@ -0,0 +1,115 @@ +import 'dart:convert'; +import 'dart:ffi'; +import 'dart:io'; + +import 'whisper_dart_bindings.dart'; + +const String _libName = 'whisper_dart'; + +final DynamicLibrary _dylib = () { + if (Platform.isMacOS || Platform.isIOS) { + return DynamicLibrary.open('$_libName.framework/$_libName'); + } + if (Platform.isAndroid || Platform.isLinux) { + return DynamicLibrary.open('lib$_libName.so'); + } + if (Platform.isWindows) { + return DynamicLibrary.open('$_libName.dll'); + } + throw UnsupportedError('Unknown platform: ${Platform.operatingSystem}'); +}(); + +final WhisperDartBindings _bindings = WhisperDartBindings(_dylib); + +class Whisper { + WhisperResponse request({required WhisperRequest request}) { + try { + var res = _bindings.request(whisperRequest: request.toString()); + Map result = json.decode(res); + return WhisperResponse(result); + } catch (e) { + return WhisperResponse({"@type": "error", "message": e.toString()}); + } + } +} + +class WhisperRequest { + late Map rawData; + WhisperRequest(this.rawData); + + factory WhisperRequest.fromWavFile({ + required File audio, + required File model, + bool isTranslate = false, + int threads = 4, + bool isVerbose = false, + String language = "id", + bool isSpecialTokens = false, + bool isNoTimestamps = false, + }) { + return WhisperRequest({ + "@type": "getTextFromWavFile", + "is_translate": isTranslate, + "threads": threads, + "is_verbose": isVerbose, + "language": language, + "is_special_tokens": isSpecialTokens, + "is_no_timestamps": isNoTimestamps, + "audio": audio.path, + "model": model.path, + }); + } + + Map toMap() { + return (rawData); + } + + Map toJson() { + return (rawData); + } + + @override + String toString() { + return json.encode(rawData); + } +} + +class WhisperResponse { + late Map rawData; + WhisperResponse(this.rawData); + + String? get specialType { + try { + if (rawData["@type"] is String == false) { + return null; + } + return rawData["@type"] as String; + } catch (e) { + return null; + } + } + + String? get text { + try { + if (rawData["text"] is String == false) { + return null; + } + return rawData["text"] as String; + } catch (e) { + return null; + } + } + + Map toMap() { + return (rawData); + } + + Map toJson() { + return (rawData); + } + + @override + String toString() { + return json.encode(rawData); + } +} diff --git a/lib/src/whisper_dart_bindings.dart b/lib/src/whisper_dart_bindings.dart new file mode 100644 index 0000000..75cffef --- /dev/null +++ b/lib/src/whisper_dart_bindings.dart @@ -0,0 +1,51 @@ +// ignore_for_file: always_specify_types +// ignore_for_file: camel_case_types +// ignore_for_file: non_constant_identifier_names + +import 'dart:developer'; +import 'dart:ffi'; +import 'package:ffi/ffi.dart'; + +typedef whisper_request_native = Pointer Function(Pointer body); +typedef _wrappedPrint_C = Void Function(Pointer a); + +class WhisperDartBindings { + final Pointer Function(String symbolName) _lookup; + + WhisperDartBindings(DynamicLibrary dynamicLibrary) + : _lookup = dynamicLibrary.lookup { + initPrintWrapperCallback(); + } + + WhisperDartBindings.fromLookup( + Pointer Function(String symbolName) lookup, + ) : _lookup = lookup; + + static void _wrappedPrint(Pointer arg) { + log(arg.toDartString(), name: 'ffi:whisper_dart', level: 800); + } + + void initPrintWrapperCallback() { + _whisper_initialize(wrappedPrintPointer); + } + + final wrappedPrintPointer = + Pointer.fromFunction<_wrappedPrint_C>(_wrappedPrint); + + late final _whisper_initializePtr = + _lookup>("initialize"); + + late final _whisper_initialize = + _whisper_initializePtr.asFunction(); + + String request({required String whisperRequest}) { + var res = _whisper_request(whisperRequest.toNativeUtf8()); + return res.toDartString(); + } + + late final _whisper_requestPtr = + _lookup>('request'); + + late final _whisper_request = + _whisper_requestPtr.asFunction(); +} diff --git a/lib/whisper_dart.dart b/lib/whisper_dart.dart new file mode 100644 index 0000000..6b681ea --- /dev/null +++ b/lib/whisper_dart.dart @@ -0,0 +1 @@ +export 'src/whisper_dart.dart'; diff --git a/linux/CMakeLists.txt b/linux/CMakeLists.txt new file mode 100644 index 0000000..6dd21ff --- /dev/null +++ b/linux/CMakeLists.txt @@ -0,0 +1,22 @@ +# 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. +cmake_minimum_required(VERSION 3.10) + +# Project-level configuration. +set(PROJECT_NAME "whisper_dart") +project(${PROJECT_NAME} LANGUAGES 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 +) diff --git a/local.properties b/local.properties new file mode 100644 index 0000000..a0acaa4 --- /dev/null +++ b/local.properties @@ -0,0 +1,8 @@ +## This file must *NOT* be checked into Version Control Systems, +# as it contains information specific to your local configuration. +# +# Location of the SDK. This is only used by Gradle. +# For customization when using a Version Control System, please read the +# header note. +#Sun Jan 29 04:09:49 BRT 2023 +sdk.dir=C\:\\Users\\jeiso\\AppData\\Local\\Android\\Sdk diff --git a/macos/Classes/whisper_dart.c b/macos/Classes/whisper_dart.c new file mode 100644 index 0000000..e7235d6 --- /dev/null +++ b/macos/Classes/whisper_dart.c @@ -0,0 +1,3 @@ +// Relative import to be able to reuse the C sources. +// See the comment in ../{projectName}}.podspec for more information. +#include "../../src/whisper_dart.c" diff --git a/macos/whisper_dart.podspec b/macos/whisper_dart.podspec new file mode 100644 index 0000000..db488a1 --- /dev/null +++ b/macos/whisper_dart.podspec @@ -0,0 +1,27 @@ +# +# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html. +# Run `pod lib lint whisper_dart.podspec` to validate before publishing. +# +Pod::Spec.new do |s| + s.name = 'whisper_dart' + s.version = '0.0.1' + s.summary = 'A new Flutter FFI plugin project.' + s.description = <<-DESC +A new Flutter FFI plugin project. + DESC + s.homepage = 'http://example.com' + s.license = { :file => '../LICENSE' } + s.author = { 'Your Company' => 'email@example.com' } + + # This will ensure the source files in Classes/ are included in the native + # builds of apps using this FFI plugin. Podspec does not support relative + # paths, so Classes contains a forwarder C file that relatively imports + # `../src/*` so that the C sources can be shared among all target platforms. + s.source = { :path => '.' } + s.source_files = 'Classes/**/*' + s.dependency 'FlutterMacOS' + + s.platform = :osx, '10.11' + s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES' } + s.swift_version = '5.0' +end diff --git a/package/whisper_dart/.gitignore b/package/whisper_dart/.gitignore index 96486fd..6ca9fd5 100644 --- a/package/whisper_dart/.gitignore +++ b/package/whisper_dart/.gitignore @@ -9,6 +9,7 @@ .history .svn/ migrate_working_dir/ +models/ # IntelliJ related *.iml diff --git a/package/whisper_dart/CHANGELOG.md b/package/whisper_dart/CHANGELOG.md index 05e3bc9..ad0ee9a 100644 --- a/package/whisper_dart/CHANGELOG.md +++ b/package/whisper_dart/CHANGELOG.md @@ -1,3 +1,4 @@ +<<<<<<< HEAD:package/whisper_dart/CHANGELOG.md ## 0.0.8 - update style code @@ -6,10 +7,18 @@ ## 0.0.4 - update whisper.cpp +======= +## 0.0.3 + +- support additional platforms + +>>>>>>> e00b55753994ebd5a0ec17fcc2e129383927717a:CHANGELOG.md ## 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/package/whisper_dart/README.md b/package/whisper_dart/README.md index 0957d7e..fcbca04 100644 --- a/package/whisper_dart/README.md +++ b/package/whisper_dart/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/package/whisper_dart/analysis_options.yaml b/package/whisper_dart/analysis_options.yaml index dee8927..5bcd91a 100644 --- a/package/whisper_dart/analysis_options.yaml +++ b/package/whisper_dart/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/package/whisper_dart/pubspec.yaml b/package/whisper_dart/pubspec.yaml index 3bde8bd..5e8fc80 100644 --- a/package/whisper_dart/pubspec.yaml +++ b/package/whisper_dart/pubspec.yaml @@ -1,4 +1,5 @@ name: whisper_dart +<<<<<<< HEAD:package/whisper_dart/pubspec.yaml description: Openai library whisper unofficial for recognition audio to text without heavy gpu, support server side and client side. version: 0.0.8 homepage: https://github.com/azkadev/whisper_dart.git @@ -6,15 +7,42 @@ repository: https://github.com/azkadev/whisper_dart.git environment: sdk: '>=2.19.0 <3.0.0' +======= +description: whisper.cpp (from @ggerganov) implementation using ffi, a library for recognition audio to text without heavy gpu, support server side and client side. +version: 0.0.3 +homepage: https://github.com/azkadev/whisper_dart -# dependencies: -# path: ^1.8.0 +environment: + sdk: ">=2.18.6 <3.0.0" + flutter: ">=2.11.0" +>>>>>>> e00b55753994ebd5a0ec17fcc2e129383927717a:pubspec.yaml -dev_dependencies: - lints: ^2.0.0 - test: ^1.16.0 dependencies: ffi: ^2.0.1 +<<<<<<< HEAD:package/whisper_dart/pubspec.yaml ffmpeg_dart: ^0.0.0 galaxeus_lib: ^0.0.46 universal_io: ^2.0.4 +======= + flutter: + sdk: flutter + +dev_dependencies: + flutter_test: + sdk: flutter + flutter_lints: ^2.0.0 + +flutter: + plugin: + platforms: + android: + ffiPlugin: true + ios: + ffiPlugin: true + linux: + ffiPlugin: true + macos: + ffiPlugin: true + windows: + ffiPlugin: true +>>>>>>> e00b55753994ebd5a0ec17fcc2e129383927717a:pubspec.yaml diff --git a/package/whisper_flutter/example/android/app/build.gradle b/package/whisper_flutter/example/android/app/build.gradle index 74b59a2..416fcc4 100644 --- a/package/whisper_flutter/example/android/app/build.gradle +++ b/package/whisper_flutter/example/android/app/build.gradle @@ -26,7 +26,11 @@ apply plugin: 'kotlin-android' apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" android { +<<<<<<< HEAD:package/whisper_flutter/example/android/app/build.gradle compileSdkVersion flutter.compileSdkVersion +======= + compileSdkVersion 33 +>>>>>>> e00b55753994ebd5a0ec17fcc2e129383927717a:example/android/app/build.gradle ndkVersion "25.1.8937393" compileOptions { @@ -40,15 +44,19 @@ android { sourceSets { +<<<<<<< HEAD:package/whisper_flutter/example/android/app/build.gradle main { java.srcDirs += 'src/main/kotlin' // jniLibs.srcDirs = ['src/main/jniLibs'] } +======= + main.java.srcDirs += 'src/main/kotlin' +>>>>>>> e00b55753994ebd5a0ec17fcc2e129383927717a:example/android/app/build.gradle } 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-gradle-build-configuration. minSdkVersion flutter.minSdkVersion @@ -64,6 +72,7 @@ android { signingConfig signingConfigs.debug } } + namespace 'com.example.whisper_dart_example' } flutter { diff --git a/package/whisper_flutter/example/android/app/src/debug/AndroidManifest.xml b/package/whisper_flutter/example/android/app/src/debug/AndroidManifest.xml index 45d523a..399f698 100644 --- a/package/whisper_flutter/example/android/app/src/debug/AndroidManifest.xml +++ b/package/whisper_flutter/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/package/whisper_flutter/example/android/app/src/main/kotlin/com/example/whisper_dart_example/MainActivity.kt b/package/whisper_flutter/example/android/app/src/main/kotlin/com/example/whisper_dart_example/MainActivity.kt new file mode 100644 index 0000000..baebc25 --- /dev/null +++ b/package/whisper_flutter/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/package/whisper_flutter/example/android/app/src/profile/AndroidManifest.xml b/package/whisper_flutter/example/android/app/src/profile/AndroidManifest.xml index 45d523a..399f698 100644 --- a/package/whisper_flutter/example/android/app/src/profile/AndroidManifest.xml +++ b/package/whisper_flutter/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); +======= + const char *text = whisper_full_get_segment_text(ctx, i); + + std::string str(text); + text_result += str; + if (params.no_timestamps) + { + printf("%s", text); + fflush(stdout); + } + else + { + const int64_t t0 = whisper_full_get_segment_t0(ctx, i); + const int64_t t1 = whisper_full_get_segment_t1(ctx, i); + + printf("[%s --> %s] %s\n", to_timestamp(t0).c_str(), to_timestamp(t1).c_str(), text); + } +>>>>>>> e00b55753994ebd5a0ec17fcc2e129383927717a:src/main.cpp } } } @@ -336,7 +415,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 +)