Fangjun Kuang
Committed by GitHub

Fix Flutter TTS example for iOS (#1090)

... ... @@ -79,9 +79,23 @@ with the following APIs
### Links for pre-built Flutter APPs
| Description | URL | 中国用户 |
|--------------------------------|-----------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------|
| Streaming speech recognition | [Address](https://k2-fsa.github.io/sherpa/onnx/flutter/asr/app.html) | [点此](https://k2-fsa.github.io/sherpa/onnx/flutter/asr/app-cn.html) |
#### Real-time speech recognition
| Description | URL | 中国用户 |
|--------------------------------|---------------------------------------------------------------------|---------------------------------------------------------------------|
| Streaming speech recognition | [Address](https://k2-fsa.github.io/sherpa/onnx/flutter/asr/app.html)| [点此](https://k2-fsa.github.io/sherpa/onnx/flutter/asr/app-cn.html)|
#### Text-to-speech
| Description | URL | 中国用户 |
|--------------------------------|--------------------------------------------------------------|-----------------------------------------------------------------------------|
| Android (arm64-v8a, armeabi-v7a, x86_64) | [Address](https://k2-fsa.github.io/sherpa/onnx/flutter/tts-android.html) | [点此](https://k2-fsa.github.io/sherpa/onnx/flutter/tts-android-cn.html)|
| Linux (x64) | [Address](https://k2-fsa.github.io/sherpa/onnx/flutter/tts-linux.html) | [点此](https://k2-fsa.github.io/sherpa/onnx/flutter/tts-linux-cn.html) |
| macOS (x64) | [Address](https://k2-fsa.github.io/sherpa/onnx/flutter/tts-macos-x64.html) | [点此](https://k2-fsa.github.io/sherpa/onnx/flutter/tts-macos-x64-cn.html) |
| macOS (arm64) | [Address](https://k2-fsa.github.io/sherpa/onnx/flutter/tts-macos-arm64.html) | [点此](https://k2-fsa.github.io/sherpa/onnx/flutter/tts-macos-arm64-cn.html)|
| Windows (x64) | [Address](https://k2-fsa.github.io/sherpa/onnx/flutter/tts-win.html) | [点此](https://k2-fsa.github.io/sherpa/onnx/flutter/tts-win-cn.html) |
> Note: You need to build from source for iOS.
### Links for pre-trained models
... ...
... ... @@ -10,6 +10,12 @@ It works on the following platforms:
- macOS (both arm64 and x86_64 are supported)
- Windows
Screenshots are given below:
|Android|iOS|Linux|macOS|Windows|
|-------|---|-----|-----|-------|
|![](./android.jpg)|![](./ios.jpg)|![](./ubuntu.jpg)|![](./macos.jpg)|![](./windows.jpg)|
## How to build
Before you run `flutter build`, you have to select a TTS model and change
... ... @@ -108,8 +114,75 @@ flutter build apk --split-per-abi
- 5. For iOS
First, connect your iPhone to your computer and use `flutter devices` to show
available devices. You will see something like below:
```
Found 3 connected devices:
iPhone (mobile) • 00008030-001064212E85802E • ios • iOS 16.3 20D47
macOS (desktop) • macos • darwin-x64 • macOS 13.1 22C65 darwin-x64
Chrome (web) • chrome • web-javascript • Google Chrome 126.0.6478.127
No wireless devices were found.
Run "flutter emulators" to list and start any available device emulators.
If you expected another device to be detected, please run "flutter doctor" to diagnose potential issues. You may also try increasing the time to wait for connected devices with the "--device-timeout" flag. Visit https://flutter.dev/setup/ for troubleshooting tips.
```
Then you can use
```
flutter run -d 00008030-001064212E85802E --release
```
You would see something like below:
```
Launching lib/main.dart on iPhone in release mode...
Automatically signing iOS for device deployment using specified development team in Xcode project: N5ZH3Z63A6
Running pod install... 1,773ms
Running Xcode build...
Xcode build done. 7.9s
Failed to build iOS app
Could not build the precompiled application for the device.
Error (Xcode): No profiles for 'com.k2fsa.sherpa.onnx.tts' were found: Xcode couldn't find any iOS App Development provisioning profiles matching
'com.k2fsa.sherpa.onnx.tts'. Automatic signing is disabled and unable to generate a profile. To enable automatic signing, pass
-allowProvisioningUpdates to xcodebuild.
/Users/fangjun/open-source/sherpa-onnx/flutter-examples/tts/ios/Runner.xcodeproj
It appears that there was a problem signing your application prior to installation on the device.
Verify that the Bundle Identifier in your project is your signing id in Xcode
open ios/Runner.xcworkspace
Also try selecting 'Product > Build' to fix the problem.
Error running application on iPhone.
```
After you have followed the instructions in the above log, run gain
> Note: I have run `open ios/Runner.xcworkspace` and click `Product -> Build`.
```
flutter run -d 00008030-001064212E85802E --release
```
Finally, it will show something like below:
```
flutter build ios
Launching lib/main.dart on iPhone in release mode...
Automatically signing iOS for device deployment using specified development team in Xcode project: N5ZH3Z63A6
Running Xcode build...
└─Compiling, linking and signing... 6.5s
Xcode build done. 18.3s
Installing and launching... 22.9s
Flutter run key commands.
h List all available interactive commands.
c Clear the screen
q Quit (terminate the application on the device).
```
## Fix for Linux
... ...
... ... @@ -373,6 +373,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
SWIFT_VERSION = 5.0;
OTHER_LDFLAGS = "-lc++";
VERSIONING_SYSTEM = "apple-generic";
};
name = Profile;
... ... @@ -390,6 +391,7 @@
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
OTHER_LDFLAGS = "-lc++";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Runner.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/Runner";
};
name = Debug;
... ... @@ -405,6 +407,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.k2fsa.sherpa.onnx.tts.RunnerTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
OTHER_LDFLAGS = "-lc++";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Runner.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/Runner";
};
name = Release;
... ... @@ -420,6 +423,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.k2fsa.sherpa.onnx.tts.RunnerTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
OTHER_LDFLAGS = "-lc++";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Runner.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/Runner";
};
name = Profile;
... ... @@ -554,6 +558,7 @@
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
OTHER_LDFLAGS = "-lc++";
VERSIONING_SYSTEM = "apple-generic";
};
name = Debug;
... ... @@ -576,6 +581,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
SWIFT_VERSION = 5.0;
OTHER_LDFLAGS = "-lc++";
VERSIONING_SYSTEM = "apple-generic";
};
name = Release;
... ...
... ... @@ -91,7 +91,7 @@ Future<sherpa_onnx.OfflineTts> createOfflineTts() async {
final all = ruleFsts.split(',');
var tmp = <String>[];
for (final f in all) {
tmp.add(p.join(directory.path, modelDir, f));
tmp.add(p.join(directory.path, f));
}
ruleFsts = tmp.join(',');
}
... ... @@ -106,7 +106,7 @@ Future<sherpa_onnx.OfflineTts> createOfflineTts() async {
}
if (lexicon != '') {
lexicon = p.join(directory.path, lexicon);
lexicon = p.join(directory.path, modelDir, lexicon);
}
if (dataDir != '') {
... ...
... ... @@ -37,6 +37,7 @@ class _TtsScreenState extends State<TtsScreen> {
_controller_text_input = TextEditingController();
_controller_hint = TextEditingController();
_controller_sid = TextEditingController(text: '0');
super.initState();
}
... ... @@ -73,6 +74,9 @@ class _TtsScreenState extends State<TtsScreen> {
keyboardType: TextInputType.number,
maxLines: 1,
controller: _controller_sid,
onTapOutside: (PointerDownEvent event) {
FocusManager.instance.primaryFocus?.unfocus();
},
inputFormatters: <TextInputFormatter>[
FilteringTextInputFormatter.digitsOnly
]),
... ... @@ -99,6 +103,9 @@ class _TtsScreenState extends State<TtsScreen> {
),
maxLines: 5,
controller: _controller_text_input,
onTapOutside: (PointerDownEvent event) {
FocusManager.instance.primaryFocus?.unfocus();
},
),
const SizedBox(height: 5),
Row(
... ...