Human voices¶
Setup¶
Prerequisites¶
Build and run¶
Start a terminal/command prompt and go to the human_voices
directory,
within the flutter examples directory - that is the name of this example project.
Note - the gem_kit
directory containing the Maps SDK for Flutter
should be in the plugins
directory of the example, e.g.
example_pathname/plugins/gem_kit
- see the environment setup guide above.
Replace example_pathname
with the actual example path name,
such as address_search
Download project dependencies:
flutter upgrade
run the following terminal commands in the project directory,
where the pubspec.yaml
file is located:
flutter clean
flutter pub get
Run the example:
flutter run
If such a question appears, select the chrome
browser; in the above example, press 2.
First, verify that the ANDROID_SDK_ROOT
environment variable
is set to the root path of your android SDK.
In android/build.gradle
add the maven {}
block as shown,
within the allprojects {} block
, for both debug and release builds,
without the line numbers, those are for reference:
1allprojects {
2 repositories {
3 google()
4 mavenCentral()
5 maven {
6 url "${rootDir}/../plugins/gem_kit/android/build"
7 }
8 }
9}
in android/app/build.gradle
within the android {}
block, in the defaultConfig {}
block,
the android SDK version minSdk
must be set as shown below.
Additionally, for release builds, in android/app/build.gradle
,
within the android {}
block, add the buildTypes {}
block as shown:
Replace example_pathname
with the actual example pathname, such as center_coordinates
1android {
2 defaultConfig {
3 applicationId "com.magiclane.gem_kit.examples.example_pathname"
4 minSdk 21
5 targetSdk flutter.targetSdk
6 versionCode flutterVersionCode.toInteger()
7 versionName flutterVersionName
8 }
9 buildTypes {
10 release {
11 // TODO: Add your own signing config for the release build.
12 // Signing with the debug keys for now, so `flutter run --release` works.
13 minifyEnabled false
14 shrinkResources false
15 signingConfig signingConfigs.debug
16 }
17 }
18}
Then build the apk:
flutter build apk --debug
flutter build apk --release
build/app/outputs/apk/debug
or
build/app/outputs/apk/release
subdirectory,
for debug or release build respectively,
within the current project directory, such as center_coordinates
app-release.apk
or app-debug.apk
adb push app-release.apk sdcard
And then click on the apk in the file browser on the device to install and run it.
In the ios/Podfile
configuration text file, at the top, set the minimum ios
platform to 13 like this:
platform :ios, '13.0'
pod install
in the [ios folder] ./ios/
flutter build ios
to build a Runner.app.flutter run
to build and run on an attached device.<path/to>/ios/Runner.xcworkspace
project in Xcode
and execute and debug from there.How it works¶
In the example project directory, such as center_coordinates
, there is a text file named
pubspec.yaml
which contains project configuration and dependencies.
The most important lines from this file are shown here:
1name: center_coordinates
2description: A Flutter example using Maps SDK for Flutter.
3
4version: 1.0.0+1
5
6environment:
7 sdk: '>=3.0.5 <4.0.0'
8
9dependencies:
10 flutter:
11 sdk: flutter
12 gem_kit:
13 path: plugins/gem_kit
14
15 cupertino_icons: ^1.0.2
16
17 intl: ^0.19.0
18 flutter_tts: ^4.0.2
19
20 dev_dependencies:
21 flutter_test:
22 sdk: flutter
23
24 flutter_lints: ^3.0.2
25
26# The following section is specific to Flutter packages.
27flutter:
28 uses-material-design: true
The project must have a name and version. The dependencies list the Flutter SDK, and the gem_kit, Maps for Flutter SDK.
The source code is in example_pathname/lib/main.dart
Replace example_pathname
with the actual example path name, such as center_coordinates
1import 'package:gem_kit/core.dart';
2import 'package:gem_kit/map.dart';
3import 'package:gem_kit/navigation.dart';
4import 'package:gem_kit/routing.dart';
5
6import 'bottom_navigation_panel.dart';
7import 'top_navigation_panel.dart';
8import 'tts_engine.dart';
9import 'utility.dart';
10
11import 'package:flutter/material.dart' hide Route;
The dart
material package is imported, as well as the
required gem_kit
packages.
The tts_engine
(text-to-speech) is used to speak the voice instructions.
1class _MyHomePageState extends State<MyHomePage> {
2 late GemMapController _mapController;
3
4 @override
5 void dispose() {
6 GemKit.release();
7 super.dispose();
8 }
9
10 void _startSimulation() {
11 final routes = _mapController.preferences.routes;
12
13 _navigationHandler = NavigationService.startSimulation(routes.mainRoute, (type, instruction) async {
14 if (type == NavigationEventType.destinationReached || type == NavigationEventType.error) {
15 // If the navigation has ended or if and error occured while navigating, remove routes.
16 setState(() {
17 _isSimulationActive = false;
18 _cancelRoute();
19 });
20
21 return;
22 }
23 _isSimulationActive = true;
24
25 if (instruction != null) {
26 setState(() => currentInstruction = instruction);
27 }
28 }, onTextToSpeechInstruction: (textInstruction) {
29 // Play the text instruction;
30 _ttsEngine.speakText(textInstruction);
31 }, speedMultiplier: 20);
32
33 // Set the camera to follow position.
34 _mapController.startFollowingPosition();
35 }
36}
_startSimulation()
function, the onTextToSpeechInstruction:
receives a text instruction, and uses the text-to-speech engine to say it:_ttsEngine.speakText(textInstruction);