android continuous speech recognition system built offline

Introduction
This article describes how to deploy htk Kit HCopy and HDecode tools to android phone, enabling mobile terminal offline speech recognition function. c is an open source language htk kit in the android NDK to integrate the tool in the package.

NDK build environment can refer Andye the blog in the history of the most straightforward Android jni development environment to build data -NDK. Speak very comprehensive. I will not repeat here

HCopy Kit

View HTK file in MakeFile know HCopy rely on the following documents
HCopy.c esig_asc.c esignal.c esig_edr.c esig_nat.c HAdapt.c HArc.c HAudio.c HDict.c HExactMPE.c HFB.c HFBLat.c HLabel. c HLat.c HLM.c HMap.c HMath.c HMem.c HModel.c HNet.c HParm.c HRec.c HShell.c HSigP.c HTrain.c HUtil.c HVQ.c HWave.c strarr.c
the these files are copied to jni directory. Android.mk and modify files:

1
2
3
4
5
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := TestNdk
LOCAL_SRC_FILES := com_example_uploadfileactivity_JniClient.c HCopy.c esig_asc.c esignal.c esig_edr.c esig_nat.c HAdapt.c HArc.c HAudio.c HDict.c HExactMPE.c HFB.c HFBLat.c HLabel.c HLat.c HLM.c HMap.c HMath.c HMem.c HModel.c HNet.c HParm.c HRec.c HShell.c HSigP.c HTrain.c HUtil.c HVQ.c HWave.c strarr.c
include $(BUILD_SHARED_LIBRARY)

Build on what you can compile the source code and generates libTestNdk.so HCopy file in the obj / local / armeabi / directory, add the following code to the need to call the DLL class:

1
2
3
static {
System.loadLibrary("TestNdk");
}

Of course HCopy suitable for use in linux terminal environment, in practical engineering, HCopy need to modify the source code. Enabling him to continuously extract features of multiple files and initialization is performed only once.
First HCopy in the initialization part of the main function to move all HCopyInit function, and the like OpenSpeechFile PutTargetFile extraction features and functions to move HCopyWhile function.
Then jni interface functions to call him.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
int argc=5;
char *argv[100]={"HCopy","-C","/storage/emulated/0/hucd/config-plp","/storage/emulated/0/hucd/a.wav","/storage/emulated/0/hucd/a.plp"};

JNIEXPORT jstring JNICALL Java_com_example_uploadfileactivity_JniClient_HCopyInit
(JNIEnv *env, jclass arg, jstring instringA, jstring instringB)
{
HCopyinit(argc, argv);
jstring str = (*env)->NewStringUTF(env, "HCopyInit Finished!");
return str;
}
JNIEXPORT jstring JNICALL Java_com_example_uploadfileactivity_JniClient_HCopyDoFile
(JNIEnv *env, jclass arg, jstring instringA, jstring instringB)
{
HCopywhile(argc, argv);
jstring str = (*env)->NewStringUTF(env, "HCopyDofile Finished");
return str;
}

HDecode Kit

By looking at HDecode in the Makefile know HDecode dependent files while compiling HDecode need to carry parameters -DNO_LAT_LM, based on this Android.mk add the following in the file:

. 1 
2
. 3
. 4
. 5
large column  android continuous speech recognition system built offline
include $(CLEAR_VARS)
LOCAL_MODULE := TestHDNdk
LOCAL_CFLAGS += -DNO_LAT_LM
LOCAL_SRC_FILES := com_example_uploadfileactivity_JniClientHDecode.c HDecode.c HLVNet.c HLVRec.c HLVLM.c HLVModel.c esig_asc.c esignal.c esig_edr.c esig_nat.c HAdapt.c HArc.c HAudio.c HDict.c HExactMPE.c HFB.c HFBLat.c HLabel.c HLat.c HMap.c HMath.c HMem.c HModel.c HNet.c HParm.c HRec.c HShell.c HSigP.c HTrain.c HUtil.c HVQ.c HWave.c strarr.c
include $(BUILD_SHARED_LIBRARY)

And copy the file to the folder jni. Build on what you can compile the source code and generates libTestHDNdk.so HDecode file in the obj / local / armeabi / directory, add the following code to the need to call the DLL class:

1
2
3
static {
System.loadLibrary("TestHDNdk");
}

Also HDecode suitable for use in linux terminal environment, in practical engineering, HDecode need to modify the source code. Referring to complete HCopy modification method.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
int argc=27;
/*char *argv[100]={"HCopy","-C","/mnt/sdcard/config-plp","/mnt/sdcard/a.wav","/mnt/sdcard/a.plp"};*/
char *argv[100]={"HDecode" ,"-T", "1", "-C", "/storage/emulated/0/hucd/hdecode.hlda.cfg", "-H", "/storage/emulated/0/hucd/S2.hlda.MMF", "-y","rec","-t", "250.0", "250.0", "-u", "3500", "-v", "125.0", "-s", "12.0", "-p", "-10.0", "-w", "/storage/emulated/0/hucd/new", "-i", "/storage/emulated/0/hucd/out", "/storage/emulated/0/hucd/new.dct", "/storage/emulated/0/hucd/xwrd.clustered.mlist" ,"/storage/emulated/0/hucd/a.plp"};
JNIEXPORT jstring JNICALL Java_com_example_uploadfileactivity_JniClientHDecode_HDecodeInit
(JNIEnv *env, jclass arg, jstring instringA, jstring instringB)
{
char tmp[10];
int i=HDecodeinit(argc, argv);
sprintf(tmp,"%d",i);
jstring str = (*env)->NewStringUTF(env, tmp);
return str;
}
JNIEXPORT jstring JNICALL Java_com_example_uploadfileactivity_JniClientHDecode_HDecodeDoFile
(JNIEnv *env, jclass arg, jstring instringA, jstring instringB)
{
HDecodewhile(argc, argv);
jstring str = (*env)->NewStringUTF(env, "HDecodeDoFile from JNI !");
return str;
}

Recognition results

In practical engineering, to save the audio recording of the phone to /hucd/a.wav in, and in turn call HCopyDoFile and HDecodeDoFile function can be found in the identification results / hucd / out files generated.
Since the environment is not generally exist android gunzip other tools, and therefore do not attempt to use Fillter in hdecode.hlda.cfg, if HLANGMODFILTER = 'gunzip -c $ .gz' Please remove similar configuration, and the language model uncompressed.

Guess you like

Origin www.cnblogs.com/wangziqiang123/p/11696544.html