-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
litongjava
committed
Oct 22, 2023
1 parent
98cbb1d
commit 42814f3
Showing
9 changed files
with
220 additions
and
1,749 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
app/src/main/java/com/litongjava/whisper/cpp/android/java/bean/WhisperSegment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.litongjava.whisper.cpp.android.java.bean; | ||
|
||
/** | ||
* Created by [email protected] on 10/21/2023_7:48 AM | ||
*/ | ||
public class WhisperSegment { | ||
private long start, end; | ||
private String sentence; | ||
|
||
public WhisperSegment() { | ||
} | ||
|
||
public WhisperSegment(long start, long end, String sentence) { | ||
this.start = start; | ||
this.end = end; | ||
this.sentence = sentence; | ||
} | ||
|
||
public long getStart() { | ||
return start; | ||
} | ||
|
||
public long getEnd() { | ||
return end; | ||
} | ||
|
||
public String getSentence() { | ||
return sentence; | ||
} | ||
|
||
public void setStart(long start) { | ||
this.start = start; | ||
} | ||
|
||
public void setEnd(long end) { | ||
this.end = end; | ||
} | ||
|
||
public void setSentence(String sentence) { | ||
this.sentence = sentence; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "["+start+" --> "+end+"]:"+sentence; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
app/src/main/java/com/litongjava/whisper/cpp/android/java/demo/app/App.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.litongjava.whisper.cpp.android.java.demo.app; | ||
|
||
import android.app.Application; | ||
|
||
import com.blankj.utilcode.util.Utils; | ||
|
||
public class App extends Application { | ||
@Override | ||
public void onCreate() { | ||
super.onCreate(); | ||
Utils.init(this); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
app/src/main/java/com/litongjava/whisper/cpp/android/java/single/LocalWhisper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.litongjava.whisper.cpp.android.java.single; | ||
|
||
import android.app.Application; | ||
import android.os.Build; | ||
|
||
import androidx.annotation.RequiresApi; | ||
|
||
import com.blankj.utilcode.util.Utils; | ||
import com.litongjava.whisper.cpp.android.java.bean.WhisperSegment; | ||
import com.litongjava.whisper.cpp.android.java.utils.AssetUtils; | ||
import com.whispercppdemo.whisper.WhisperContext; | ||
|
||
import java.io.File; | ||
import java.util.List; | ||
import java.util.concurrent.ExecutionException; | ||
|
||
//import com.litongjava.whisper.android.java.bean.WhisperSegment; | ||
//import com.litongjava.whisper.android.java.utils.AssetUtils; | ||
|
||
public enum LocalWhisper { | ||
INSTANCE; | ||
|
||
public static final String modelFilePath = "models/ggml-tiny.bin"; | ||
private WhisperContext whisperContext; | ||
|
||
@RequiresApi(api = Build.VERSION_CODES.O) | ||
LocalWhisper() { | ||
Application context = Utils.getApp(); | ||
File filesDir = context.getFilesDir(); | ||
File modelFile = AssetUtils.copyFileIfNotExists(context, filesDir, modelFilePath); | ||
String realModelFilePath = modelFile.getAbsolutePath(); | ||
whisperContext = WhisperContext.createContextFromFile(realModelFilePath); | ||
} | ||
|
||
public synchronized String transcribeData(float[] data) throws ExecutionException, InterruptedException { | ||
return whisperContext.transcribeData(data); | ||
} | ||
|
||
public List<WhisperSegment> transcribeDataWithTime(float[] audioData) throws ExecutionException, InterruptedException { | ||
return whisperContext.transcribeDataWithTime(audioData); | ||
} | ||
|
||
public void init() { | ||
//noting to do.but init | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.