From 62effd9acbb4e03cbc17c69ebd218293223788dd Mon Sep 17 00:00:00 2001 From: Reuben Morais Date: Wed, 29 Sep 2021 17:04:01 +0200 Subject: [PATCH] AAR build+publish --- .../actions/upload-release-asset/action.yml | 23 +-- .github/workflows/build-and-test.yml | 193 ++++++++++++++++-- RELEASE_NOTES.md | 0 doc/BUILDING.rst | 26 +-- doc/C-Examples.rst | 4 +- doc/DEPLOYMENT.rst | 26 +++ doc/DotNet-Examples.rst | 4 +- doc/Java-Examples.rst | 4 +- doc/NodeJS-Examples.rst | 4 +- doc/Python-API.rst | 2 + doc/Python-Examples.rst | 4 +- .../ExampleInstrumentedTest.java | 2 +- .../coqui/sttexampleapp/ExampleUnitTest.java | 2 +- .../main/java/ai/coqui/libstt/STTModel.java | 4 +- 14 files changed, 219 insertions(+), 79 deletions(-) create mode 100644 RELEASE_NOTES.md diff --git a/.github/actions/upload-release-asset/action.yml b/.github/actions/upload-release-asset/action.yml index 43f86f27..9fc584f3 100644 --- a/.github/actions/upload-release-asset/action.yml +++ b/.github/actions/upload-release-asset/action.yml @@ -19,10 +19,6 @@ inputs: description: "Tag of release to check artifacts under" required: false default: "v0.10.0-alpha.7" - should-create-release: - description: "Whether this action should automatically create a release for the given tag if one doesn't already exist" - required: false - default: false runs: using: "composite" steps: @@ -51,7 +47,6 @@ runs: owner=$(echo "${{inputs.repo}}" | cut -f1 -d/) repo=$(echo "${{inputs.repo}}" | cut -f2 -d/) tag="${{ inputs.release-tag }}" - should_create="${{ inputs.should-create-release }}" GH_REPO="https://api.github.com/repos/${owner}/${repo}" @@ -75,21 +70,9 @@ runs: response=$(curl -sH "$AUTH" $GH_TAGS) eval $(echo "$response" | grep -m 1 "id.:" | grep -w id | tr : = | tr -cd '[[:alnum:]]=') [ "$id" ] || { - # If release does not exist, create it - if [[ "$should_create" == "true" ]]; then - echo "Tag does not have corresponding release, creating release for tag: $tag..." - response=$(curl -X POST -sH "$AUTH" -H "Content-Type: application/json" "${GH_REPO}/releases" -d '{"tag_name":"'"$tag"'","name":"Coqui STT '"$tag"'","prerelease":true}') - eval $(echo "$response" | grep -m 1 "id.:" | grep -w id | tr : = | tr -cd '[[:alnum:]]=') - [ "$id" ] || { - echo "Error: Could not create release for tag: $tag" - echo "$response" | awk 'length($0)<100' >&2 - exit 1 - } - else - echo "Error: Could not find release for tag: $tag" - echo "$response" | awk 'length($0)<100' >&2 - exit 1 - fi + echo "Error: Could not find release for tag: $tag" + echo "$response" | awk 'length($0)<100' >&2 + exit 1 } # Upload assets diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index c52c682b..768eaa75 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -23,6 +23,57 @@ defaults: run: shell: bash jobs: + create-release: + name: "Create release for tag" + runs-on: ubuntu-20.04 + outputs: + release-tag: ${{ steps.check-version.outputs.release-tag }} + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + - uses: actions/setup-python@v2 + with: + python-version: 3.8 + - name: Check VERSION file matches pushed Git tag and check if prerelease + id: check-version + run: | + set -xe + if [[ "${{ startsWith(github.ref, 'refs/tags/') }}" != "true" ]]; then + echo "Should never happen (this job only runs on tag pushes)" + exit 1 + fi + + VERSION="v$(cat VERSION)" + if [[ "${{ github.ref }}" != "refs/tags/${VERSION}" ]]; then + echo "Pushed tag does not match VERSION file. Aborting release." + exit 1 + fi + + # Tag for this release (version with leading v) + tag=$(echo "${{ github.ref }}" | sed -e 's|^refs/tags/||') + echo ::set-output name=release-tag::${tag} + + # Version without leading v + version=$(cat VERSION) + echo ::set-output name=version::${version} + + # Is this a prerelease or not? + cat <> $GITHUB_ENV + # This particular version of CMake confuses Gradle by not being semver. + # We're fine with 3.10.2 which is also installed. Keep an eye on the + # virtual environments though: + # https://github.com/actions/virtual-environments/blob/main/images/macos/macos-10.15-Readme.md#android + - name: Remove CMake 3.18.1-g262b901 + run: | + ${ANDROID_SDK_ROOT}/cmdline-tools/latest/bin/sdkmanager --uninstall 'cmake;3.18.1' + - run: | + make GRADLE="./gradlew " -C native_client/java + - run: | + make GRADLE="./gradlew " -C native_client/java maven-bundle + - uses: actions/upload-artifact@v2 + with: + name: "app.apk" + path: ${{ github.workspace }}/native_client/java/app/build/outputs/apk/release/app*.apk + - uses: actions/upload-artifact@v2 + with: + name: "libstt.aar" + path: ${{ github.workspace }}/native_client/java/libstt/build/outputs/aar/libstt*.aar + - uses: actions/upload-artifact@v2 + with: + name: "libstt.maven.zip" + path: ${{ github.workspace }}/native_client/java/libstt/build/libstt-*.maven.zip + publish-android-aar: + name: "Android|Publish AAR" + runs-on: ubuntu-20.04 + needs: [create-release, build-android-apk-aar] + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + - uses: actions/download-artifact@v2 + with: + name: "libstt.aar" + path: ${{ github.workspace }}/ + - run: ls -lh + - name: Get tag name + id: get-tag + run: | + tag=$(echo "${{ github.ref }}" | sed -e 's|^refs/tags/||') + echo "::set-output name=tag::$tag" + - uses: ./.github/actions/upload-release-asset + with: + name: '' # use filename + path: "*.aar" + release-tag: ${{ needs.create-release.outputs.release-tag }} diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md new file mode 100644 index 00000000..e69de29b diff --git a/doc/BUILDING.rst b/doc/BUILDING.rst index 7428529c..87281a6d 100644 --- a/doc/BUILDING.rst +++ b/doc/BUILDING.rst @@ -126,7 +126,7 @@ Included are a set of generated Python bindings. After following the above build make bindings pip install dist/stt-* -The API mirrors the C++ API and is demonstrated in `client.py `_. Refer to `coqui-stt.h `_ for documentation. +`Reference documentation `_ is available for the Python bindings, as well as examples in the `STT-examples repository `_ and the `source code for the CLI tool installed alongside the Python bindings `_. Install NodeJS / ElectronJS bindings ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -186,7 +186,7 @@ Cross-building RPi3 ARMv7 and LePotato ARM64 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -We do support cross-compilation. Please refer to our ``coqui-ai/tensorflow`` fork, where we define the following ``--config`` flags: +We support cross-compilation from Linux hosts. The following ``--config`` flags can be specified when building with bazel: * ``--config=rpi3_opt`` for Raspbian / ARMv7 * ``--config=rpi3-armv8_opt`` for ARMBian / ARM64 @@ -213,28 +213,8 @@ The path of the system tree can be overridden from the default values defined in cd ../STT/native_client make TARGET= stt -Android devices support ------------------------ - -Using the library from Android project -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -Due to the discontinuation of Bintray JCenter we do not have pre-built Android packages published for now. We are working to move to Maven Central and will update this section when it's available. - -.. We provide uptodate and tested ``libstt`` 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: - - .. code-block:: - - implementation 'stt.coqui.ai:libstt:VERSION@aar' - Building ``libstt.so`` for Android -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +---------------------------------- Prerequisites ^^^^^^^^^^^^^ diff --git a/doc/C-Examples.rst b/doc/C-Examples.rst index ae16b7e7..fd24b057 100644 --- a/doc/C-Examples.rst +++ b/doc/C-Examples.rst @@ -13,8 +13,8 @@ Creating a model instance and loading model :start-after: sphinx-doc: c_ref_model_start :end-before: sphinx-doc: c_ref_model_stop -Deploying trained model ------------------------ +Transcribing audio with the loaded model +---------------------------------------- .. literalinclude:: ../native_client/client.cc :language: c diff --git a/doc/DEPLOYMENT.rst b/doc/DEPLOYMENT.rst index acf36f19..dab8be1c 100644 --- a/doc/DEPLOYMENT.rst +++ b/doc/DEPLOYMENT.rst @@ -14,6 +14,7 @@ You can deploy 🐸STT models either via a command-line client or a language bin * :ref:`The Python package + language binding ` * :ref:`The Node.JS package + language binding ` +* :ref:`The Android libstt AAR package ` * :ref:`The command-line client ` * :ref:`The native C API ` @@ -133,6 +134,31 @@ See the `release notes `_ to find whic See the :ref:`TypeScript client ` for an example of how to use the bindings programatically. +.. _android-usage: + +Using the Android AAR libstt package +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +A pre-built ``libstt`` Android AAR package can be downloaded from GitHub Releases, for Android versions 7.0+. In order to use it in your Android application, first modify your app's ``build.gradle`` file to add a local dir as a repository. In the ``repository`` section, add the following definition: + +.. code-block:: groovy + + repositories { + flatDir { + dirs 'libs' + } + } + +Then, create a libs directory inside your app's folder, and place the libstt AAR file there. Finally, add the following dependency declaration in your app's ``build.gradle`` file: + +.. code-block:: groovy + + dependencies { + implementation fileTree(dir: 'libs', include: ['*.aar']) + } + +This will link all .aar files in the ``libs`` directory you just created, including libstt. + .. _cli-usage: Using the command-line client diff --git a/doc/DotNet-Examples.rst b/doc/DotNet-Examples.rst index 7d4e14c9..ef422900 100644 --- a/doc/DotNet-Examples.rst +++ b/doc/DotNet-Examples.rst @@ -13,8 +13,8 @@ Creating a model instance and loading model :start-after: sphinx-doc: csharp_ref_model_start :end-before: sphinx-doc: csharp_ref_model_stop -Deploying trained model ------------------------ +Transcribing audio with the loaded model +---------------------------------------- .. literalinclude:: ../native_client/dotnet/STTConsole/Program.cs :language: csharp diff --git a/doc/Java-Examples.rst b/doc/Java-Examples.rst index 5d90d9eb..64eb0bd2 100644 --- a/doc/Java-Examples.rst +++ b/doc/Java-Examples.rst @@ -13,8 +13,8 @@ Creating a model instance and loading model :start-after: sphinx-doc: java_ref_model_start :end-before: sphinx-doc: java_ref_model_stop -Deploying trained model ------------------------ +Transcribing audio with the loaded model +---------------------------------------- .. literalinclude:: ../native_client/java/app/src/main/java/ai/coqui/sttexampleapp/STTActivity.java :language: java diff --git a/doc/NodeJS-Examples.rst b/doc/NodeJS-Examples.rst index 211b6691..830c3486 100644 --- a/doc/NodeJS-Examples.rst +++ b/doc/NodeJS-Examples.rst @@ -15,8 +15,8 @@ Creating a model instance and loading model :start-after: sphinx-doc: js_ref_model_start :end-before: sphinx-doc: js_ref_model_stop -Deploying trained model ------------------------ +Transcribing audio with the loaded model +---------------------------------------- .. literalinclude:: ../native_client/javascript/client.ts :language: javascript diff --git a/doc/Python-API.rst b/doc/Python-API.rst index 9aec57f0..ea87a0f5 100644 --- a/doc/Python-API.rst +++ b/doc/Python-API.rst @@ -1,3 +1,5 @@ +.. _python-api: + Python ====== diff --git a/doc/Python-Examples.rst b/doc/Python-Examples.rst index fe871a46..3e3e60c8 100644 --- a/doc/Python-Examples.rst +++ b/doc/Python-Examples.rst @@ -15,8 +15,8 @@ Creating a model instance and loading model :start-after: sphinx-doc: python_ref_model_start :end-before: sphinx-doc: python_ref_model_stop -Deploying trained model ------------------------ +Transcribing audio with the loaded model +---------------------------------------- .. literalinclude:: ../native_client/python/client.py :language: python diff --git a/native_client/java/app/src/androidTest/java/ai/coqui/sttexampleapp/ExampleInstrumentedTest.java b/native_client/java/app/src/androidTest/java/ai/coqui/sttexampleapp/ExampleInstrumentedTest.java index 0a68a324..77c8e376 100644 --- a/native_client/java/app/src/androidTest/java/ai/coqui/sttexampleapp/ExampleInstrumentedTest.java +++ b/native_client/java/app/src/androidTest/java/ai/coqui/sttexampleapp/ExampleInstrumentedTest.java @@ -1,4 +1,4 @@ -package ai.coqui.sttexampleapp +package ai.coqui.sttexampleapp; import android.content.Context; import android.support.test.InstrumentationRegistry; diff --git a/native_client/java/app/src/test/java/ai/coqui/sttexampleapp/ExampleUnitTest.java b/native_client/java/app/src/test/java/ai/coqui/sttexampleapp/ExampleUnitTest.java index a2b67ba8..0f0a6ebd 100644 --- a/native_client/java/app/src/test/java/ai/coqui/sttexampleapp/ExampleUnitTest.java +++ b/native_client/java/app/src/test/java/ai/coqui/sttexampleapp/ExampleUnitTest.java @@ -1,4 +1,4 @@ -package ai.coqui.sttexampleapp +package ai.coqui.sttexampleapp; import org.junit.Test; diff --git a/native_client/java/libstt/src/main/java/ai/coqui/libstt/STTModel.java b/native_client/java/libstt/src/main/java/ai/coqui/libstt/STTModel.java index 3fce310f..c986a95c 100644 --- a/native_client/java/libstt/src/main/java/ai/coqui/libstt/STTModel.java +++ b/native_client/java/libstt/src/main/java/ai/coqui/libstt/STTModel.java @@ -15,8 +15,8 @@ public class STTModel { private SWIGTYPE_p_ModelState _msp; private void evaluateErrorCode(int errorCode) { - STT_Error_Codes code = STT_Error_Codes.swigToEnum(errorCode); - if (code != STT_Error_Codes.ERR_OK) { + Error_Codes code = Error_Codes.swigToEnum(errorCode); + if (code != Error_Codes.ERR_OK) { throw new RuntimeException("Error: " + impl.ErrorCodeToErrorMessage(errorCode) + " (0x" + Integer.toHexString(errorCode) + ")."); } }