Skip to content

Commit

Permalink
Merge remote-tracking branch 'dan/master' into fix-doc
Browse files Browse the repository at this point in the history
  • Loading branch information
csukuangfj committed Sep 3, 2024
2 parents 20a646d + 7ebae46 commit dbfcce3
Show file tree
Hide file tree
Showing 80 changed files with 3,291 additions and 1,250 deletions.
42 changes: 40 additions & 2 deletions .github/workflows/build-doc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ jobs:
cd /workspace
which latexmk
apk add --no-cache python3 py3-pip git make gcc zlib-dev libffi-dev openssl-dev musl-dev ghostscript
apk add --no-cache python3 py3-pip git make gcc zlib-dev libffi-dev openssl-dev musl-dev ghostscript curl
python3 --version
Expand All @@ -86,7 +86,20 @@ jobs:
python3 -m pip install -r ./docs/requirements.txt
cd docs
# Download test wave files for SenseVoice
mkdir -p source/_static/sense-voice
pushd source/_static/sense-voice
rm .gitignore
curl -SL -O https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/lei-jun-test.wav
curl -SL -O https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/Obama.wav
curl -SL -O https://huggingface.co/csukuangfj/sherpa-onnx-sense-voice-zh-en-ja-ko-yue-2024-07-17/resolve/main/test_wavs/zh.wav
curl -SL -O https://huggingface.co/csukuangfj/sherpa-onnx-sense-voice-zh-en-ja-ko-yue-2024-07-17/resolve/main/test_wavs/en.wav
ls -lh
popd
make html
touch build/html/.nojekyll
export GIT_LFS_SKIP_SMUDGE=1
Expand Down Expand Up @@ -150,6 +163,14 @@ jobs:
cd ..
rm -rf huggingface
git clone https://huggingface.co/csukuangfj/sherpa-onnx-bin huggingface
cd huggingface
./build-generate-subtitles.py
mv -v download-generated-subtitles.html ../build/html/onnx/lazarus/
mv -v download-generated-subtitles-cn.html ../build/html/onnx/lazarus/
cd ..
rm -rf huggingface
git clone https://huggingface.co/csukuangfj/sherpa-onnx-wheels huggingface
cd huggingface
./run.sh
Expand All @@ -168,16 +189,33 @@ jobs:
pushd source/onnx/pretrained_models/offline-transducer/
sed -i.bak /sherpa-onnx-zipformer-thai-2024-06-20\.txt/d zipformer-transducer-models.rst
sed -i.bak /sherpa-onnx-zipformer-thai-2024-06-20-int8\.txt/d zipformer-transducer-models.rst
sed -i.bak /sherpa-onnx-zipformer-ja-reazonspeech-2024-08-01\.txt/d zipformer-transducer-models.rst
sed -i.bak /sherpa-onnx-zipformer-ja-reazonspeech-2024-08-01-int8\.txt/d zipformer-transducer-models.rst
popd
git diff
make latex
mkdir -pv build/html/_static
cd build/latex
latexmk -interaction=nonstopmode -f -pdf -dvi- -ps- sherpa.tex || true
#latexmk -interaction=nonstopmode -f -pdf -dvi- -ps- sherpa.tex || true
latexmk -interaction=nonstopmode -f -pdf -dvi- -ps- sherpa.tex >/dev/null 2>&1 || true
ls -lh sherpa.pdf
cp -v sherpa.pdf /workspace/
- name: View generated files
shell: bash
run: |
cd docs/build/html
ls -lh
echo "-----_static-----"
ls -lh _static
echo "-----_static/sense-voice-----"
ls -lh _static/sense-voice
- name: Release sherpa.pdf
if: (github.repository_owner == 'csukuangfj' || github.repository_owner == 'k2-fsa') && github.event_name == 'push'
uses: svenstaro/upload-release-action@v2
Expand Down
12 changes: 12 additions & 0 deletions docs/source/_static/css/custom.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.toggle .header {
display: block;
clear: both;
}

.toggle .header:after {
content: " ▶";
}

.toggle .header.open:after {
content: " ▼";
}
1 change: 1 addition & 0 deletions docs/source/_static/sense-voice/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.wav
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added docs/source/_static/vits-melo-tts/zh-en-0.wav
Binary file not shown.
Binary file added docs/source/_static/vits-melo-tts/zh-en-1.wav
Binary file not shown.
Binary file added docs/source/_static/vits-melo-tts/zh-en-2.wav
Binary file not shown.
Binary file added docs/source/_static/vits-melo-tts/zh-en-3.wav
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File renamed without changes.
15 changes: 15 additions & 0 deletions docs/source/_templates/page.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!-- see https://stackoverflow.com/questions/2454577/sphinx-restructuredtext-show-hide-code-snippets -->
{% extends "!page.html" %}

{% block footer %}
<script type="text/javascript">
$(document).ready(function() {
$(".toggle > *").hide();
$(".toggle .header").show();
$(".toggle .header").click(function() {
$(this).parent().children().not(".header").toggle(400);
$(this).parent().children(".header").toggleClass("open");
})
});
</script>
{% endblock %}
7 changes: 7 additions & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,11 @@ def get_version():
.. _Dart: https://dart.dev/
.. _Node: https://nodejs.org/en
.. _SenseVoice: https://github.com/FunAudioLLM/SenseVoice
.. _LibriTTS-R: https://www.openslr.org/141/
.. _ReazonSpeech: https://github.com/reazon-research/ReazonSpeech
.. _Lazarus: https://www.lazarus-ide.org/
"""


def setup(app):
app.add_css_file("custom.css")
112 changes: 64 additions & 48 deletions docs/source/onnx/android/build-sherpa-onnx.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ and ``text-to-speech`` (TTS).
you can download pre-built shared libraries by visiting the release page
`<https://github.com/k2-fsa/sherpa-onnx/releases/>`_

For instance, for the relase ``v1.9.14``, you can visit
`<https://github.com/k2-fsa/sherpa-onnx/releases/tag/v1.9.14>`_
and download the file ``sherpa-onnx-v1.9.14-android.tar.bz2``
For instance, for the relase ``v1.10.19``, you can visit
`<https://github.com/k2-fsa/sherpa-onnx/releases/tag/v1.10.19>`_
and download the file ``sherpa-onnx-v1.10.19-android.tar.bz2``
using the following command:

.. code-block:: bash
wget https://github.com/k2-fsa/sherpa-onnx/releases/download/v1.9.14/sherpa-onnx-v1.9.14-android.tar.bz2
wget https://github.com/k2-fsa/sherpa-onnx/releases/download/v1.10.19/sherpa-onnx-v1.10.19-android.tar.bz2
Please always use the latest release.

Expand Down Expand Up @@ -58,6 +58,7 @@ Android Studio.
For reference, we post the version we are using below:

.. image:: ./pic/android-studio-version.png
:align: center
:alt: screenshot of my version of Android Studio
:width: 600

Expand Down Expand Up @@ -197,12 +198,10 @@ After building, you will find the following shared libraries:

.. code-block:: bash
ls -lh build-android-arm64-v8a/install/lib/lib*.so
-rwxr-xr-x 1 fangjun staff 848K Feb 26 15:54 build-android-arm64-v8a/install/lib/libkaldi-native-fbank-core.so
-rw-r--r--@ 1 fangjun staff 13M Feb 26 15:54 build-android-arm64-v8a/install/lib/libonnxruntime.so
-rwxr-xr-x 1 fangjun staff 29K Feb 26 15:54 build-android-arm64-v8a/install/lib/libsherpa-onnx-c-api.so
-rwxr-xr-x 1 fangjun staff 313K Feb 26 15:54 build-android-arm64-v8a/install/lib/libsherpa-onnx-core.so
-rwxr-xr-x 1 fangjun staff 34K Feb 26 15:54 build-android-arm64-v8a/install/lib/libsherpa-onnx-jni.so
ls -lh build-android-arm64-v8a/install/lib/
-rw-r--r-- 1 fangjun staff 15M Jul 28 12:54 libonnxruntime.so
-rwxr-xr-x 1 fangjun staff 3.7M Jul 28 12:54 libsherpa-onnx-jni.so
Please copy them to ``android/SherpaOnnx/app/src/main/jniLibs/arm64-v8a/``:

Expand All @@ -212,16 +211,11 @@ Please copy them to ``android/SherpaOnnx/app/src/main/jniLibs/arm64-v8a/``:
You should see the following screen shot after running the above copy ``cp`` command.

.. figure:: ./pic/so-libs-for-arm64-v8a.png
.. figure:: ./pic/so-libs-for-arm64-v8a.jpg
:align: center
:alt: Generated shared libraries for arm64-v8a
:width: 600

.. hint::

You may see more files than it is shown in the screenshot. That is totally fine
since we are extending `sherpa-onnx`_. The first thing to remember is to always
use the wildcard ``lib*.so`` in the ``cp`` command.

Build for armv7-eabi
^^^^^^^^^^^^^^^^^^^^

Expand All @@ -234,13 +228,10 @@ After building, you will find the following shared libraries:

.. code-block:: bash
ls -lh build-android-armv7-eabi/install/lib/lib*.so
ls -lh build-android-armv7-eabi/install/lib
-rwxr-xr-x 1 fangjun staff 513K Mar 4 21:48 build-android-armv7-eabi/install/lib/libkaldi-native-fbank-core.so
-rw-r--r-- 1 fangjun staff 9.1M Mar 4 21:48 build-android-armv7-eabi/install/lib/libonnxruntime.so
-rwxr-xr-x 1 fangjun staff 19K Mar 4 21:48 build-android-armv7-eabi/install/lib/libsherpa-onnx-c-api.so
-rwxr-xr-x 1 fangjun staff 298K Mar 4 21:48 build-android-armv7-eabi/install/lib/libsherpa-onnx-core.so
-rwxr-xr-x 1 fangjun staff 22K Mar 4 21:48 build-android-armv7-eabi/install/lib/libsherpa-onnx-jni.so
-rw-r--r-- 1 fangjun staff 10M Jul 28 13:18 libonnxruntime.so
-rwxr-xr-x 1 fangjun staff 2.1M Jul 28 13:18 libsherpa-onnx-jni.so
Please copy them to ``android/SherpaOnnx/app/src/main/jniLibs/armeabi-v7a``:

Expand All @@ -250,7 +241,8 @@ Please copy them to ``android/SherpaOnnx/app/src/main/jniLibs/armeabi-v7a``:
You should see the following screen shot after running the above copy ``cp`` command.

.. figure:: ./pic/so-libs-for-armv7a-eabi.png
.. figure:: ./pic/so-libs-for-armv7a-eabi.jpg
:align: center
:alt: Generated shared libraries for armv7-eabi
:width: 600

Expand All @@ -266,22 +258,21 @@ After building, you will find the following shared libraries:

.. code-block:: bash
ls -lh build-android-x86-64/install/lib/lib*.so
ls -lh build-android-x86-64/install/lib/
-rwxr-xr-x 1 fangjun staff 901K Feb 26 16:00 build-android-x86-64/install/lib/libkaldi-native-fbank-core.so
-rw-r--r--@ 1 fangjun staff 15M Feb 26 16:00 build-android-x86-64/install/lib/libonnxruntime.so
-rwxr-xr-x 1 fangjun staff 347K Feb 26 16:00 build-android-x86-64/install/lib/libsherpa-onnx-core.so
-rwxr-xr-x 1 fangjun staff 32K Feb 26 16:00 build-android-x86-64/install/lib/libsherpa-onnx-jni.so
-rw-r--r-- 1 fangjun staff 17M Jul 28 13:26 libonnxruntime.so
-rwxr-xr-x 1 fangjun staff 4.0M Jul 28 13:26 libsherpa-onnx-jni.so
Please copy them to ``android/SherpaOnnx/app/src/main/jniLibs/x86_64/``:

.. code-block:: bash
build-android-x86-64/install/lib/lib*.so android/SherpaOnnx/app/src/main/jniLibs/x86_64/
cp build-android-x86-64/install/lib/lib*.so android/SherpaOnnx/app/src/main/jniLibs/x86_64/
You should see the following screen shot after running the above copy ``cp`` command.

.. figure:: ./pic/so-libs-for-x86-64.png
.. figure:: ./pic/so-libs-for-x86-64.jpg
:align: center
:alt: Generated shared libraries for x86_64
:width: 600

Expand All @@ -293,6 +284,28 @@ Build for x86
cd sherpa-onnx # Go to the root repo
./build-android-x86.sh
After building, you will find the following shared libraries:

.. code-block:: bash
ls -lh build-android-x86/install/lib/
-rw-r--r-- 1 fangjun staff 17M Jul 28 13:28 libonnxruntime.so
-rwxr-xr-x 1 fangjun staff 3.9M Jul 28 13:28 libsherpa-onnx-jni.so
Please copy them to ``android/SherpaOnnx/app/src/main/jniLibs/x86/``:

.. code-block:: bash
cp build-android-x86/install/lib/lib*.so android/SherpaOnnx/app/src/main/jniLibs/x86/
You should see the following screen shot after running the above copy ``cp`` command.

.. figure:: ./pic/so-libs-for-x86.jpg
:align: center
:alt: Generated shared libraries for x86
:width: 600

Download pre-trained models
---------------------------

Expand All @@ -314,8 +327,6 @@ Use the following command to download the pre-trained model and place it into
cd android/SherpaOnnx/app/src/main/assets/
sudo apt-get install git-lfs
wget https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20.tar.bz2
tar xvf sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20.tar.bz2
Expand All @@ -324,29 +335,31 @@ Use the following command to download the pre-trained model and place it into
cd sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20
# Now, remove extra files to reduce the file size of the generated apk
rm -rf .git test_wavs
rm -rf test_wavs
rm -f *.sh README.md
rm -f bpe.model
rm -f encoder-epoch-99-avg-1.int8.onnx
rm -f joiner-epoch-99-avg-1.int8.onnx
rm -f decoder-epoch-99-avg-1.int8.onnx
rm -f bpe.vocab
In the end, you should have the following files:

.. code-block:: bash
ls -lh
total 696984
-rw-r--r-- 1 fangjun staff 13M Feb 21 21:45 decoder-epoch-99-avg-1.onnx
-rw-r--r-- 1 fangjun staff 315M Feb 23 21:18 encoder-epoch-99-avg-1.onnx
-rw-r--r-- 1 fangjun staff 12M Feb 21 21:45 joiner-epoch-99-avg-1.onnx
-rw-r--r-- 1 fangjun staff 55K Feb 21 21:45 tokens.txt
du -h .
340M .
-rw-r--r--@ 1 fangjun staff 13M Jul 28 13:51 decoder-epoch-99-avg-1.onnx
-rw-r--r--@ 1 fangjun staff 315M Jul 28 13:51 encoder-epoch-99-avg-1.onnx
-rw-r--r--@ 1 fangjun staff 12M Jul 28 13:51 joiner-epoch-99-avg-1.onnx
-rw-r--r--@ 1 fangjun staff 55K Nov 21 2023 tokens.txt
You should see the following screen shot after downloading the pre-trained model:

.. figure:: ./pic/pre-trained-model-2023-02-20.png
:alt: Files after downloading the pre-trained model
:align: center
:width: 600

.. hint::
Expand All @@ -366,6 +379,7 @@ Finally, it is time to build `sherpa-onnx`_ to generate an APK package.
Select ``Build -> Make Project``, as shown in the following screen shot.

.. figure:: ./pic/build-make-project.png
:align: center
:alt: Select ``Build -> Make Project``
:width: 600

Expand All @@ -375,7 +389,7 @@ You can find the generated APK in ``android/SherpaOnnx/app/build/outputs/apk/deb
ls -lh android/SherpaOnnx/app/build/outputs/apk/debug/app-debug.apk
-rw-r--r-- 1 fangjun staff 331M Feb 26 16:17 android/SherpaOnnx/app/build/outputs/apk/debug/app-debug.apk
-rw-r--r--@ 1 fangjun staff 329M Jul 28 13:56 android/SherpaOnnx/app/build/outputs/apk/debug/app-debug.apk
Congratulations! You have successfully built an APK for Android.

Expand All @@ -385,31 +399,33 @@ Analyze the APK
---------------

.. figure:: ./pic/analyze-apk.png
:align: center
:alt: Select ``Build -> Analyze APK ...``
:width: 600

Select ``Build -> Analyze APK ...`` in the above screen shot, in the
popped-up dialog select the generated APK ``app-debug.apk``,
and you will see the following screen shot:

.. figure:: ./pic/analyze-apk-result.png
.. figure:: ./pic/analyze-apk-result.jpg
:align: center
:alt: Result of analyzing apk
:width: 700

You can see from the above screen shot that most part of the APK
is occupied by the pre-trained model, while the runtime, including the shared
libraries, is only ``5.4 MB``.
libraries, is only ``7.2 MB``.

.. caution::

You can see that ``libonnxruntime.so`` alone occupies ``5MB`` out of ``5.4MB``.
You can see that ``libonnxruntime.so`` alone occupies ``5.8MB`` out of ``7.2MB``.

We use a so-called ``Full build`` instead of ``Mobile build``, so the file
size of the library is somewhat a bit larger.

``libonnxruntime.so`` is donwloaded from

`<https://mvnrepository.com/artifact/com.microsoft.onnxruntime/onnxruntime-android/1.14.0>`_
`<https://mvnrepository.com/artifact/com.microsoft.onnxruntime/onnxruntime-android/1.17.1>`_

Please refer to `<https://onnxruntime.ai/docs/build/custom.html>`_ for a
custom build to reduce the file size of ``libonnxruntime.so``.
Expand Down
5 changes: 2 additions & 3 deletions docs/source/onnx/android/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ Android
=======


In this section, we describe how to build an Android app for ``real-time`` speech
recognition with `sherpa-onnx`_.
In this section, we describe how to build an Android app for with `sherpa-onnx`_.

.. hint::

During speech recognition, it does not need to access the Internet.
For real-time speech recognition, it does not need to access the Internet.
Everyting is processed locally on your phone.

.. toctree::
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed docs/source/onnx/android/pic/analyze-apk-result.png
Binary file not shown.
1 change: 0 additions & 1 deletion docs/source/onnx/android/pic/android-studio-version.png

This file was deleted.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed docs/source/onnx/android/pic/so-libs-for-x86-64.png
Binary file not shown.
Binary file added docs/source/onnx/android/pic/so-libs-for-x86.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit dbfcce3

Please sign in to comment.