Skip to content

Commit

Permalink
[iOS] Add SpeechRecognition example (#9)
Browse files Browse the repository at this point in the history
Add an iOS speech recognition example that uses the Wav2Vec 2.0 model.
  • Loading branch information
edgchen1 authored Jul 8, 2021
1 parent c802952 commit 16b9197
Show file tree
Hide file tree
Showing 29 changed files with 1,250 additions and 45 deletions.
86 changes: 49 additions & 37 deletions ci_build/azure_pipelines/mobile-examples-pipeline.yml
Original file line number Diff line number Diff line change
@@ -1,37 +1,49 @@
jobs:
- job: BasicUsageIos
pool:
vmImage: "macOS-10.15"

steps:
- task: UsePythonVersion@0
inputs:
versionSpec: '3.6'
addToPath: true
architecture: 'x64'

- script: |
set -e
pip install -r ../model/requirements.txt
../model/gen_model.sh ./OrtBasicUsage/model
workingDirectory: mobile/examples/basic_usage/ios
displayName: "Generate model"
- task: CocoaPods@0
inputs:
workingDirectory: 'mobile/examples/basic_usage/ios'
forceRepoUpdate: false

- task: Xcode@5
inputs:
actions: 'test'
configuration: 'Debug'
sdk: 'iphonesimulator'
xcWorkspacePath: 'mobile/examples/basic_usage/ios/OrtBasicUsage.xcworkspace'
scheme: 'OrtBasicUsage'
xcodeVersion: 'specifyPath'
xcodeDeveloperDir: '/Applications/Xcode_12.4.app/Contents/Developer'
packageApp: false
destinationPlatformOption: 'iOS'
destinationTypeOption: 'simulators'
destinationSimulators: 'iPhone 8'
jobs:

# mobile/examples/basic_usage/ios
- job: BasicUsageIos
pool:
vmImage: "macOS-10.15"

steps:
- template: templates/use-python-step.yml

- bash: |
set -e
pip install -r ../model/requirements.txt
../model/gen_model.sh ./OrtBasicUsage/model
workingDirectory: mobile/examples/basic_usage/ios
displayName: "Generate model"
- script: pod install
workingDirectory: 'mobile/examples/basic_usage/ios'
displayName: "Install CocoaPods pods"

- template: templates/xcode-build-and-test-step.yml
parameters:
xcWorkspacePath: 'mobile/examples/basic_usage/ios/OrtBasicUsage.xcworkspace'
scheme: 'OrtBasicUsage'

# mobile/examples/speech_recognition/ios
- job: SpeechRecognitionIos
pool:
vmImage: "macOS-10.15"

steps:
- template: templates/use-python-step.yml

- bash: |
set -e
pip install -r ../model/requirements.txt
../model/gen_model.sh ./SpeechRecognition/model
workingDirectory: mobile/examples/speech_recognition/ios
displayName: "Generate model"
- script: pod install
workingDirectory: 'mobile/examples/speech_recognition/ios'
displayName: "Install CocoaPods pods"

- template: templates/xcode-build-and-test-step.yml
parameters:
xcWorkspacePath: 'mobile/examples/speech_recognition/ios/SpeechRecognition.xcworkspace'
scheme: 'SpeechRecognition'
7 changes: 7 additions & 0 deletions ci_build/azure_pipelines/templates/use-python-step.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
steps:
- task: UsePythonVersion@0
inputs:
versionSpec: '3.6'
addToPath: true
architecture: 'x64'
displayName: "Use Python 3.6"
21 changes: 21 additions & 0 deletions ci_build/azure_pipelines/templates/xcode-build-and-test-step.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
parameters:
- name: xcWorkspacePath
type: string
- name: scheme
type: string

steps:
- task: Xcode@5
inputs:
actions: 'test'
configuration: 'Debug'
sdk: 'iphonesimulator'
xcWorkspacePath: '${{ parameters.xcWorkspacePath }}'
scheme: '${{ parameters.scheme }}'
xcodeVersion: 'specifyPath'
xcodeDeveloperDir: '/Applications/Xcode_12.4.app/Contents/Developer'
packageApp: false
destinationPlatformOption: 'iOS'
destinationTypeOption: 'simulators'
destinationSimulators: 'iPhone 8'
displayName: "Xcode build and test"
36 changes: 32 additions & 4 deletions mobile/README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,43 @@
# ONNX Runtime Mobile examples
# ONNX Runtime Mobile Examples

The following examples demonstrate how to use ONNX Runtime (ORT) Mobile in mobile applications.
These examples demonstrate how to use ONNX Runtime (ORT) Mobile in mobile applications.

## Basic usage
## General Prerequisites

These are some general prerequisites.
Examples may specify other requirements if applicable.
Please refer to the instructions for each example.

### Get the Code

Clone this repo.

```bash
git clone https://github.com/microsoft/onnxruntime-inference-examples.git
```

### iOS Example Prerequisites

- Xcode 12.4+
- CocoaPods
- A valid Apple Developer ID if you want to run the example on a device

## Examples

### Basic Usage

The example app shows basic usage of the ORT APIs.

- [iOS Basic Usage](examples/basic_usage/ios)

## Image classification
### Image Classification

The example app uses image classification which is able to continuously classify the objects it sees from the device's camera in real-time and displays the most probable inference results on the screen.

- [Android Image Classifier](examples/image_classifications/android)

### Speech Recognition

The example app uses speech recognition to transcribe speech from audio recorded by the device.

- [iOS Speech Recognition](examples/speech_recognition/ios)
2 changes: 1 addition & 1 deletion mobile/examples/basic_usage/ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ platform :ios, '11.0'
target 'OrtBasicUsage' do
use_frameworks!

pod 'onnxruntime-mobile-objc', '1.8.0-preview'
pod 'onnxruntime-mobile-objc'

target 'OrtBasicUsageTests' do
inherit! :search_paths
Expand Down
1 change: 0 additions & 1 deletion mobile/examples/basic_usage/model/gen_model.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,3 @@ cd ${OUTPUT_DIR}

python3 ${DIR}/single_add_gen.py
python3 -m onnxruntime.tools.convert_onnx_models_to_ort .

4 changes: 2 additions & 2 deletions mobile/examples/basic_usage/model/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
onnx==1.9.0
onnxruntime==1.8.0
onnx>=1.9.0
onnxruntime>=1.8.0
12 changes: 12 additions & 0 deletions mobile/examples/speech_recognition/ios/Podfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
platform :ios, '11.0'

target 'SpeechRecognition' do
use_frameworks!

pod 'onnxruntime-mobile-objc'

target 'SpeechRecognitionTests' do
inherit! :search_paths
end

end
Loading

0 comments on commit 16b9197

Please sign in to comment.