Skip to content
This repository has been archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
update of streaming ASR for PT 1.11 (#240)
Browse files Browse the repository at this point in the history
* initial commit

* Revert "initial commit"

This reverts commit 5a65775.

* main readme and helloworld/demo app readme updates

* update of streaming ASR for PT 1.11
  • Loading branch information
jeffxtang authored Mar 14, 2022
1 parent 486fc7a commit 86aff27
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ The [PyTorch demo app](https://github.com/pytorch/android-demo-app/tree/master/P

[Speech Recognition](https://github.com/pytorch/android-demo-app/tree/master/SpeechRecognition) demonstrates how to convert Facebook AI's wav2vec 2.0, one of the leading models in speech recognition, to TorchScript and how to use the scripted model in an Android app to perform speech recognition.

### Streaming Speech recognition

[Streaming Speech Recognition](https://github.com/pytorch/android-demo-app/tree/master/StreamingASR) demonstrates how to how to use a new torchaudio pipeline to perform streaming speech recognition, powered by Java Native Call to a C++ audio processing library for the mel spectrogram transform.

### Video Classification

[TorchVideo](https://github.com/pytorch/android-demo-app/tree/master/TorchVideo) demonstrates how to use a pre-trained video classification model, available at the newly released [PyTorchVideo](https://github.com/facebookresearch/pytorchvideo), on Android to see video classification results, updated per second while the video plays, on tested videos, videos from the Photos library, or even real-time videos.
Expand Down
16 changes: 8 additions & 8 deletions StreamingASR/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ In the Speech Recognition Android [demo app](https://github.com/pytorch/android-

## Prerequisites

* PyTorch 1.10.1 and torchaudio 0.10.1 or above (Optional)
* PyTorch 1.11 and torchaudio 0.11 or above (Optional)
* Python 3.8 (Optional)
* Android Pytorch library org.pytorch:pytorch_android_lite:1.10.0
* Android Pytorch library org.pytorch:pytorch_android_lite:1.11.0
* Android Studio 4.0.1 or later

## Quick Start
Expand All @@ -22,7 +22,7 @@ git clone https://github.com/pytorch/android-demo-app
cd android-demo-app/StreamingASR
```

If you don't have PyTorch 1.10.1 and torchaudio 0.10.1 installed or want to have a quick try of the demo app, you can download the optimized scripted model file [streaming_asr.ptl](https://drive.google.com/file/d/1awT_1S6H5IXSOOqpFLmpeg0B-kQVWG2y/view?usp=sharing), then drag and drop it to the `StreamingASR/app/src/main/assets` folder inside `android-demo-app/StreamingASR`, and continue to Step 3.
If you don't have PyTorch 1.11 and torchaudio 0.11 installed or want to have a quick try of the demo app, you can download the optimized scripted model file [streaming_asr.ptl](https://drive.google.com/file/d/1awT_1S6H5IXSOOqpFLmpeg0B-kQVWG2y/view?usp=sharing), then drag and drop it to the `StreamingASR/app/src/main/assets` folder inside `android-demo-app/StreamingASR`, and continue to Step 3.

Also you need to download [Eigen](https://eigen.tuxfamily.org/), a C++ template library for linear algebra, for Android NDK build required to run the app (see last section of this README for more info):
```
Expand All @@ -32,16 +32,16 @@ git clone https://github.com/jeffxtang/eigen

### 2. Test and Prepare the Model

To install PyTorch 1.10.1, torchaudio 0.10.1, and other required Python packages (numpy and pyaudio), do something like this:
To install PyTorch 1.11, torchaudio 0.11, and other required Python packages (numpy and pyaudio), do something like this:

```
conda create -n pt1.10.1 python=3.8.5
conda activate pt1.10.1
conda create -n pt1.11 python=3.8.5
conda activate pt1.11
pip install torch torchaudio numpy pyaudio
```

Now download the streaming ASR model file
[scripted_wrapper_tuple_no_transform.pt](https://drive.google.com/file/d/1_49DwHS_a3p3THGdHZj3TXmjNJj60AhP/view?usp=sharing) (the script used to create the model will be published soon) to the `android-demo-app/StreamingASR` directory.
[scripted_wrapper_tuple_no_transform.pt](https://drive.google.com/file/d/1_49DwHS_a3p3THGdHZj3TXmjNJj60AhP/view?usp=sharing) to the `android-demo-app/StreamingASR` directory.

To test the model, run `python run_sasr.py`. After you see:
```
Expand All @@ -59,7 +59,7 @@ mv streaming_asr.ptl StreamingASR/app/src/main/assets

### 3. Build and run with Android Studio

Start Android Studio, open the project located in `android-demo-app/StreamingASR/StreamingASR`, build and run the app on an Android device. After the app runs, tap the Start button and start saying something. Some example recognition results are:
Start Android Studio, open the project located in `android-demo-app/StreamingASR/StreamingASR`, build and run the app on an Android device (not an emulator). After the app runs, tap the Start button and start saying something. Some example recognition results are:

![](screenshot1.png)
![](screenshot2.png)
Expand Down
2 changes: 1 addition & 1 deletion StreamingASR/StreamingASR/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,5 @@ dependencies {
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'

implementation 'org.pytorch:pytorch_android_lite:1.10.0'
implementation 'org.pytorch:pytorch_android_lite:1.11'
}
2 changes: 1 addition & 1 deletion StreamingASR/save_model_for_mobile.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ def get_demo_wrapper():
wrapper = get_demo_wrapper()
scripted_model = torch.jit.script(wrapper)
optimized_model = optimize_for_mobile(scripted_model)
optimized_model._save_for_lite_interpreter("sasr.ptl")
optimized_model._save_for_lite_interpreter("streaming_asr.ptl")
print("Done _save_for_lite_interpreter")

0 comments on commit 86aff27

Please sign in to comment.