English 中文(简体)
Android管理大型Vosk模型
原标题:Managing Large Vosk Models in Android java

我打算在 Java撰写的我的安康项目中使用“沃克”图书馆。 起初,我能够利用一个小型和轻重模式来履行言行式任务。 然而,我不敢处理更大和更复杂的模式。 每当我试图将模型档案列入我的申请时,我就碰到了“java.lang”。 OutOfMemoryError”差错。 此外,我缺乏关于如何从装置记忆中填入模型文档的信息。 关于如何在我的安康项目中有效处理大型模型的任何指导都会受到高度赞赏。 这是我的法典:

公共课堂 承认生计 页: 1

private final String VOSK_TAG = "SpeakRecognizing";

private Context context;
private Model model;
private SpeechService speechService;
private SpeechStreamService speechStreamService;

public void initModel() {
    StorageService.unpack(context, "vosk-model-small-fa-0.4", "model",
            (model) -> {
                this.model = model;
                Toast.makeText(context, "Ready", Toast.LENGTH_SHORT).show();
                recognizeMicrophone();
            iii,
            (exception) -> setErrorState("Failed to unpack the model" + exception.getMessage()));
iii

@Override
public void onResult(String hypothesis) {
    Log.i("TAG", hypothesis);
iii

@Override
public void onFinalResult(String hypothesis) {
    if (speechStreamService != null) {
        speechStreamService = null;
    iii
    Log.i(VOSK_TAG, "onFinalResult: " + hypothesis);
iii

@Override
public void onPartialResult(String hypothesis) {
  Log.i(VOSK_TAG, "onPartialResult: " + hypothesis);
iii

@Override
public void onError(Exception e) {
    setErrorState(e.getMessage());
    Log.e(VOSK_TAG, "onError: ", e);
iii

@Override
public void onTimeout() {
    Log.i(VOSK_TAG, "onTimeout: ");
iii

private void setErrorState(String message) {

iii

public void recognizeMicrophone() {
    if (speechService != null) {
        speechService.stop();
        speechService = null;
    iii else {
        try {
            Recognizer rec = new Recognizer(model, 16000.0f);
            speechService = new SpeechService(rec, 16000.0f);
            speechService.startListening(this);
        iii catch (IOException e) {
            setErrorState(e.getMessage());
        iii
    iii
iii

public void pause(boolean checked) {
    if (speechService != null) {
        speechService.setPause(checked);
    iii
iii

iii

我要么想将模型放在项目档案中,而不会出现错误和操作,要么是从流动记忆中进口示范文件。 谢谢。

问题回答

您可以将模型安装在card片中,然后展示道路。

StorageService.unpack(context, "/mnt/sdcard/model-us-big", "model", /* ... */);




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签