首页 > 其他分享 >deepspeech_android_devices_support

deepspeech_android_devices_support

时间:2023-05-05 21:47:09浏览次数:51  
标签:deepspeech -- support libdeepspeech devices build file android Android

Android devices support

We have support for Android relying on TensorFlow Lite, with Java and JNI bindinds. For more details on how to experiment with those, please refer to the section below.

Please refer to TensorFlow documentation on how to setup the environment to build for Android (SDK and NDK required).

Using the library from Android project

We provide uptodate and tested libdeepspeech usable as an AAR package, for Android versions starting with 7.0 to 11.0. The package is published on JCenter, and the JCenter repository should be available by default in any Android project. Please make sure your project is setup to pull from this repository. You can then include the library by just adding this line to your gradle.build, adjusting VERSION to the version you need:

implementation 'deepspeech.mozilla.org:libdeepspeech:VERSION@aar'

Building libdeepspeech.so

You can build the libdeepspeech.so using (ARMv7):

bazel build --workspace_status_command="bash native_client/bazel_workspace_status_cmd.sh" --config=monolithic --config=android --config=android_arm --define=runtime=tflite --action_env ANDROID_NDK_API_LEVEL=21 --cxxopt=-std=c++14 --copt=-D_GLIBCXX_USE_C99 //native_client:libdeepspeech.so

Or (ARM64):

bazel build --workspace_status_command="bash native_client/bazel_workspace_status_cmd.sh" --config=monolithic --config=android --config=android_arm64 --define=runtime=tflite --action_env ANDROID_NDK_API_LEVEL=21 --cxxopt=-std=c++14 --copt=-D_GLIBCXX_USE_C99 //native_client:libdeepspeech.so

Building libdeepspeech.aar

In the unlikely event you have to rebuild the JNI bindings, source code is available under the libdeepspeech subdirectory. Building depends on shared object: please ensure to place libdeepspeech.so into the libdeepspeech/libs/{arm64-v8a,armeabi-v7a,x86_64}/ matching subdirectories.

Building the bindings is managed by gradle and should be limited to issuing ./gradlew libdeepspeech:build, producing an AAR package in ./libdeepspeech/build/outputs/aar/.

Please note that you might have to copy the file to a local Maven repository and adapt file naming (when missing, the error message should states what filename it expects and where).

Building C++ deepspeech binary

Building the deepspeech binary will happen through ndk-build (ARMv7):

cd ../DeepSpeech/native_client
$ANDROID_NDK_HOME/ndk-build APP_PLATFORM=android-21 APP_BUILD_SCRIPT=$(pwd)/Android.mk NDK_PROJECT_PATH=$(pwd) APP_STL=c++_shared TFDIR=$(pwd)/../tensorflow/ TARGET_ARCH_ABI=armeabi-v7a

And (ARM64):

cd ../DeepSpeech/native_client
$ANDROID_NDK_HOME/ndk-build APP_PLATFORM=android-21 APP_BUILD_SCRIPT=$(pwd)/Android.mk NDK_PROJECT_PATH=$(pwd) APP_STL=c++_shared TFDIR=$(pwd)/../tensorflow/ TARGET_ARCH_ABI=arm64-v8a

Android demo APK

Provided is a very simple Android demo app that allows you to test the library. You can build it with make apk and install the resulting APK file. Please refer to Gradle documentation for more details.

The APK should be produced in /app/build/outputs/apk/. This demo app might require external storage permissions. You can then push models files to your device, set the path to the file in the UI and try to run on an audio file. When running, it should first play the audio file and then run the decoding. At the end of the decoding, you should be presented with the decoded text as well as time elapsed to decode in miliseconds.

This application is very limited on purpose, and is only here as a very basic demo of one usage of the application. For example, it’s only able to read PCM mono 16kHz 16-bits file and it might fail on some WAVE file that are not following exactly the specification.

Running deepspeech via adb

You should use adb push to send data to device, please refer to Android documentation on how to use that.

Please push DeepSpeech data to /sdcard/deepspeech/, including:

  • output_graph.tflite which is the TF Lite model
  • External scorer file (available from one of our releases), if you want to use the scorer; please be aware that too big scorer will make the device run out of memory

Then, push binaries from native_client.tar.xz to /data/local/tmp/ds:

  • deepspeech
  • libdeepspeech.so
  • libc++_shared.so

You should then be able to run as usual, using a shell from adb shell:

user@device$ cd /data/local/tmp/ds/
user@device$ LD_LIBRARY_PATH=$(pwd)/ ./deepspeech [...]

Please note that Android linker does not support rpath so you have to set LD_LIBRARY_PATH. Properly wrapped / packaged bindings does embed the library at a place the linker knows where to search, so Android apps will be fine.

Delegation API

TensorFlow Lite supports Delegate API to offload some computation from the main CPU. Please refer to TensorFlow’s documentation for details.

To ease with experimentations, we have enabled some of those delegations on our Android builds: * GPU, to leverage OpenGL capabilities * NNAPI, the Android API to leverage GPU / DSP / NPU * Hexagon, the Qualcomm-specific DSP

This is highly experimental:

  • Requires passing environment variable DS_TFLITE_DELEGATE with values of gpu, nnapi or hexagon (only one at a time)
  • Might require exported model changes (some Op might not be supported)
  • We can’t guarantee it will work, nor it will be faster than default implementation

Feedback on improving this is welcome: how it could be exposed in the API, how much performance gains do you get in your applications, how you had to change the model to make it work with a delegate, etc.

See the support / contact details

标签:deepspeech,--,support,libdeepspeech,devices,build,file,android,Android
From: https://www.cnblogs.com/ChuenSan/p/17375428.html

相关文章

  • Android 数据存储
    概述文件存储特点:openFileInput()和openFileOutput()读取设备上的文件。SharedPreferences特点:以XML格式将数据存储到设备。SQLite数据库特点:运算速度快,占用资源少,还支持基本SQL语法。ContentProvider特点:应用程序之间的数据交换,可以将自己的数据共享给其他应用......
  • Android 程序活动单元Activity
    点击按钮页面跳转在xxxActivity类,创建按钮对象对按钮对象创建匿名内部类监听器记得选View.OnClickListener()在内部类建立Intent跳转对象:newIntent(原界面,目标界面)Intentintent=newIntent(LoginActivity.this,MainActivity.class);使用startActivity启动跳转......
  • android压力测试命令monkey详解
    一、Monkey是什么?Monkey就是SDK中附带的一个工具。二、Monkey测试的目的?:该工具用于进行压力测试。然后开发人员结合monkey打印的日志和系统打印的日志,结局测试中出现的问题。三、Monkey测试的特点?Monkey测试,所有的事件都是随机产生的,不带任何人的主观性。四、Monkey命令......
  • java.security.NoSuchAlgorithmException: Cannot find any provider supporting AES/
    Java使用AES/CBC/PKCS7Padding加解密时会报错,因为原生JDK不支持。1.在jdk中的jre\lib\security修改java.security文件,替换security.provider.7=org.bouncycastle.jce.provider.BouncyCastleProvider2./jdk/jre/lib/ext下添加jar包bcprov-jdk15on-1.58.jar ......
  • Android studio Failed to start [powershell.exe]
    无法打开本地终端解决办法:1、在file→settings→Tools→Terminal→Shellpath中把值设置为电脑系统 powershell.exe文件的全路径(如下图)  ......
  • Android dtbo(3) 编译和验证
    您可以使用设备树编译器(DTC)编译设备树源文件。不过,在将叠加层DT应用于目标主DT之前,您还应该通过模拟DTO的行为来验证结果。1.通过DTC进行编译构建主DT.dts的示例命令:dtc-@-Odtb-omy_main_dt.dtbmy_main_dt.dts构建叠加DT.dts的示例命令:dtc-@-Odtb......
  • 关于Android studio的虚拟机Webview出现网页无法加载,显示net::ERR_NAMENOT_RESOLVED的
    一开始出现了这个错误net::ERR_CLEARTEXT_NOT_PERMITTED参考这三个文献,https://www.cnblogs.com/suhq/p/14414882.htmlhttps://blog.csdn.net/qq_59125846/article/details/121953461https://blog.csdn.net/weixin_43169336/article/details/128379580都试了一遍后,问题消失,......
  • Android dtbo(2) dto语法
    设备树源(DTS,devicetreesource)格式是设备树的文本表示形式。设备树编译器(DTC)可将这种格式处理为二进制设备树,这是Linux内核要求的形式。1.使用引用DTC(DeviceTreecompiler+overlaypatches)项目在dtc-format.txt和manual.txt中说明了DTS格式。在dt-object-......
  • Android dtbo(1) dto简介
    设备树(DT,DeviceTree)是用于描述non-discoverable(google这样写的,意思应该就是硬件信息看不到)硬件的命名节点和属性构成的一种数据结构。操作系统(例如在Android中使用的Linux内核)会使用DT来支持Android设备使用的各种硬件配置。硬件供应商会提供自己的DT源文件,......
  • android中修改progressbar的两种方法
    1.创建自定义进度条样式在res/values/styles.xml文件中创建一个自定义样式来指定进度条的颜色。例如,以下样式设置进度的前景色为蓝色,背景色为灰色:<stylename="CustomProgressBar"parent="@android:style/Widget.ProgressBar.Horizontal"><itemname="android:progressDr......