Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support to additional platforms #4

Merged
merged 23 commits into from
Feb 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
9001029
fix: set necessary flags to build for windows
JeisonSanches Jan 30, 2023
7f83952
config: set up cmake
JeisonSanches Jan 30, 2023
4876f0b
chore: update readme
JeisonSanches Jan 30, 2023
8cd9154
chore: update bundle identifiers
JeisonSanches Jan 30, 2023
8f6f808
chore: update example redme
JeisonSanches Jan 30, 2023
4d36b56
chore: update project readme
JeisonSanches Jan 30, 2023
b0015db
feat: remove unused packages & set plugin options
JeisonSanches Jan 30, 2023
f4a26c1
android: update gradle and ndk versions
JeisonSanches Jan 30, 2023
dcf80e5
chore: update example name and description
JeisonSanches Jan 30, 2023
101de71
ide: add vscode build config
JeisonSanches Jan 30, 2023
1825c90
chore: move files
JeisonSanches Jan 30, 2023
6e74778
chore: misc changes (linter, git...)
JeisonSanches Jan 30, 2023
b34429a
refactor: change from snake_case to camelCase
JeisonSanches Jan 30, 2023
e7662ef
feat: ffi bindings
JeisonSanches Jan 30, 2023
f7a9b69
refactor: code cleanup
JeisonSanches Jan 30, 2023
2d4f474
chore: fix import
JeisonSanches Jan 30, 2023
9c202e8
feat: update dart example
JeisonSanches Jan 30, 2023
35d6acb
fix: windows hotfixes
JeisonSanches Jan 30, 2023
0c71da4
add ggerganov/whisper.cpp as submodule
JeisonSanches Jan 30, 2023
2d117c5
chore: remove unnecessary cmake flags
JeisonSanches Feb 5, 2023
b6cce92
fix: add "-fPIC" to CMAKE_C_FLAGS
JeisonSanches Feb 5, 2023
6b26b37
Revert "fix: add "-fPIC" to CMAKE_C_FLAGS"
JeisonSanches Feb 5, 2023
e00b557
fix: add necessary flags to build on linux
JeisonSanches Feb 5, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,35 @@
# 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

# Conventional directory for build output.
build/
ffmpeg/
railway/
*.o
*.o
7 changes: 2 additions & 5 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -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
42 changes: 42 additions & 0 deletions .metadata
Original file line number Diff line number Diff line change
@@ -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'
30 changes: 30 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
70 changes: 24 additions & 46 deletions README.md
Original file line number Diff line number Diff line change
@@ -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<String> 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"),
Expand All @@ -82,27 +66,20 @@ void main(List<String> 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<String> arguments) {
DateTime time = DateTime.now();
// print(res);
DateTime time = DateTime.now();

Whisper whisper = Whisper(
whisperLib: "whisper.cpp/whisper.so",
);
Expand All @@ -122,13 +99,14 @@ void main(List<String> 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)
31 changes: 2 additions & 29 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions android/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
.cxx
59 changes: 59 additions & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -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
}
}
1 change: 1 addition & 0 deletions android/settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rootProject.name = 'whisper_dart'
3 changes: 3 additions & 0 deletions android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.whisper_dart">
</manifest>
Loading