当前位置:操作系统 > 安卓/Android >>

android关于讯飞语音包的开发

这个是一个定制库的例子。

 

用法及注意事项:

1. 将语音库Aisound.so,放在:

  libs\armeabi\libAisound.so。

注意:armeabi目录下的库,都要加上lib的前缀,为了方便调用。

 

2. resource.irf 文件:

先将它打包到apk里,放在如下路径。

\res\raw\resource.irf

然后在程序运行的时候,读取并解压到软件目录,拿到路径及文件名。

 

3.使用

3.1 初始化库

System.loadLibrary("Aisound");

注意:这个("Aisound");指的就是那个libAisound.so。

 

3.2 生成resource.irf到本地存储

代码:

try {
   InputStream stream = getResources().openRawResource(R.raw.resource);

   OutputStream out = openFileOutput("resource.irf",
     Activity.MODE_PRIVATE);
//   OutputStream out = openFileOutput("/sdcard/Resource.irf", Activity.MODE_PRIVATE);
  

   byte buf[] = new byte[16384];
   int numread = 0;
   do {
    numread = stream.read(buf);
    if (numread <= 0) {
     break;
    } else {
     out.write(buf, 0, numread);
    }
   } while (true);
   out.close();

   return true;
  } catch (IOException e) {
   e.printStackTrace();
   return false;
  }

注意标红的部分,这个文件直接写到:/data/data/xxxxxx/files/resource.irf

 

3.3 初始化引擎

Tts.JniCreate("/data/data/xxxxxx/files/resource.irf");
Tts.JniSetParam(256, 1);
Tts.JniSetParam(1280, 20);

请注意标红,这个是软件的路径。也就是我需要把resource.irf文件写到这个路径下。当然也可以写到sd卡上或存储上。

3.4 使用

 不说了,自己封装吧!

 

备注:

这里要说的问题:

1.关于库的调用,由于封装的时候制定了包名和类名,所以在调用如下接口时

public static native int JniGetVersion();
 public static native int JniCreate(String resFilename);
 public static native int JniDestory();
 public static native int JniStop();
 public static native int JniSpeak(String text); 
 public static native int JniSetParam(int paramId,int value);
 public static native int JniGetParam(int paramId);
 public static native int JniIsPlaying();
 public static native boolean JniIsCreated();

必须使用默认编译的包名和类名。如果想改类名,那么对不起,要重新编接口函数哦! 当时我大意了,浪费了好多时间。

 

2.关于.irf文件使用

目前接口是使用文件路径,所以要将他打包,然后解压到本地存储。

还可以直接修改接口,使其直接使用流的方式,我看了,好像是char型

为了以后版本库可以更新,我没有去判断文件是否存在,而是程序每次启动都去生成文件。我不知道怎么去判断是新的库,利用文件大小?

 

 

作者:lxmhuendan
补充:移动开发 , Android ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,