Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update demo with new flutter vp v1.1 #229

Merged
merged 2 commits into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion demo/flutter/ios/Flutter/AppFrameworkInfo.plist
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
<key>CFBundleVersion</key>
<string>1.0</string>
<key>MinimumOSVersion</key>
<string>9.0</string>
<string>11.0</string>
</dict>
</plist>
2 changes: 1 addition & 1 deletion demo/flutter/ios/Podfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Uncomment this line to define a global platform for your project
platform :ios, '9.0'
platform :ios, '11.0'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'
Expand Down
18 changes: 14 additions & 4 deletions demo/flutter/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,26 @@ PODS:
- Cheetah-iOS (~> 1.1.0)
- Flutter
- Flutter (1.0.0)
- flutter_voice_processor (1.0.6):
- flutter_voice_processor (1.1.0):
- Flutter
- ios-voice-processor (~> 1.1.0)
- integration_test (0.0.1):
- Flutter
- ios-voice-processor (1.1.0)
- path_provider_ios (0.0.1):
- Flutter

DEPENDENCIES:
- cheetah_flutter (from `.symlinks/plugins/cheetah_flutter/ios`)
- Flutter (from `Flutter`)
- flutter_voice_processor (from `.symlinks/plugins/flutter_voice_processor/ios`)
- integration_test (from `.symlinks/plugins/integration_test/ios`)
- path_provider_ios (from `.symlinks/plugins/path_provider_ios/ios`)

SPEC REPOS:
trunk:
- Cheetah-iOS
- ios-voice-processor

EXTERNAL SOURCES:
cheetah_flutter:
Expand All @@ -26,16 +32,20 @@ EXTERNAL SOURCES:
:path: Flutter
flutter_voice_processor:
:path: ".symlinks/plugins/flutter_voice_processor/ios"
integration_test:
:path: ".symlinks/plugins/integration_test/ios"
path_provider_ios:
:path: ".symlinks/plugins/path_provider_ios/ios"

SPEC CHECKSUMS:
Cheetah-iOS: 6fb7be693878f5b1dec0ea5b6534fbba30954afc
cheetah_flutter: 5ecf97be04a1bea435da8331f180d94439f5a773
Flutter: 50d75fe2f02b26cc09d224853bb45737f8b3214a
flutter_voice_processor: afb59b604d99397a1ccf15c935ac8f2c2327f09f
flutter_voice_processor: 53afbf59ad3feb82f4a379fea9ed8dc98495210f
integration_test: a1e7d09bd98eca2fc37aefd79d4f41ad37bdbbe5
ios-voice-processor: 8e32d7f980a06d392d128ef1cd19cf6ddcaca3c1
path_provider_ios: 7d7ce634493af4477d156294792024ec3485acd5

PODFILE CHECKSUM: a75497545d4391e2d394c3668e20cfb1c2bbd4aa
PODFILE CHECKSUM: 7368163408c647b7eb699d0d788ba6718e18fb8d

COCOAPODS: 1.11.2
COCOAPODS: 1.11.3
6 changes: 3 additions & 3 deletions demo/flutter/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
STRIP_STYLE = "non-global";
Expand Down Expand Up @@ -429,7 +429,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand Down Expand Up @@ -479,7 +479,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
STRIP_STYLE = "non-global";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Release"
buildConfiguration = "Debug"
selectedDebuggerIdentifier = ""
selectedLauncherIdentifier = "Xcode.IDEFoundation.Launcher.PosixSpawn"
launchStyle = "0"
Expand Down

This file was deleted.

73 changes: 33 additions & 40 deletions demo/flutter/lib/cheetah_manager.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright 2022 Picovoice Inc.
// Copyright 2022-2023 Picovoice Inc.
//
// You may not use this file except in compliance with the license. A copy of the license is located in the "LICENSE"
// file accompanying this source.
Expand All @@ -20,13 +20,10 @@ typedef TranscriptCallback = Function(String transcript);
typedef ProcessErrorCallback = Function(CheetahException error);

class CheetahManager {
final VoiceProcessor? _voiceProcessor;
VoiceProcessor? _voiceProcessor;
Cheetah? _cheetah;

final TranscriptCallback _transcriptCallback;
final ProcessErrorCallback _processErrorCallback;
RemoveListener? _removeVoiceProcessorListener;
RemoveListener? _removeErrorListener;

static Future<CheetahManager> create(
String accessKey,
Expand All @@ -38,36 +35,25 @@ class CheetahManager {
return CheetahManager._(cheetah, transcriptCallback, processErrorCallback);
}

CheetahManager._(
this._cheetah, this._transcriptCallback, this._processErrorCallback)
: _voiceProcessor = VoiceProcessor.getVoiceProcessor(
_cheetah!.frameLength, _cheetah.sampleRate) {
if (_voiceProcessor == null) {
throw CheetahRuntimeException("flutter_voice_processor not available.");
}
_removeVoiceProcessorListener =
_voiceProcessor!.addListener((buffer) async {
List<int> cheetahFrame;
try {
cheetahFrame = (buffer as List<dynamic>).cast<int>();
} on Error {
CheetahException castError = CheetahException(
"flutter_voice_processor sent an unexpected data type.");
_processErrorCallback(castError);
CheetahManager._(this._cheetah, this._transcriptCallback,
ProcessErrorCallback processErrorCallback)
: _voiceProcessor = VoiceProcessor.instance {
_voiceProcessor?.addFrameListener((List<int> frame) async {
if (!(await _voiceProcessor?.isRecording() ?? false)) {
return;
}

if (_cheetah == null) {
throw CheetahInvalidStateException(
"Cannot process with Cheetah - resources have already been released");
processErrorCallback(CheetahInvalidStateException(
"Cannot process with Cheetah - resources have already been released"));
return;
}

try {
CheetahTranscript partialResult = await _cheetah!.process(cheetahFrame);
CheetahTranscript partialResult = await _cheetah!.process(frame);

if (partialResult.isEndpoint) {
CheetahTranscript remainingResult = await _cheetah!.flush();
var finalTranscript =
String finalTranscript =
partialResult.transcript + remainingResult.transcript;
if (remainingResult.transcript.isNotEmpty) {
finalTranscript += " ";
Expand All @@ -77,28 +63,32 @@ class CheetahManager {
_transcriptCallback(partialResult.transcript);
}
} on CheetahException catch (error) {
_processErrorCallback(error);
processErrorCallback(error);
}
});

_removeErrorListener = _voiceProcessor!.addErrorListener((errorMsg) {
CheetahException nativeError = CheetahException(errorMsg as String);
_processErrorCallback(nativeError);
_voiceProcessor?.addErrorListener((VoiceProcessorException error) {
processErrorCallback(CheetahException(error.message));
});
}

Future<void> startProcess() async {
if (await _voiceProcessor?.isRecording() ?? false) {
return;
}

if (_cheetah == null || _voiceProcessor == null) {
throw CheetahInvalidStateException(
"Cannot start Cheetah - resources have already been released");
}

if (await _voiceProcessor?.hasRecordAudioPermission() ?? false) {
try {
await _voiceProcessor!.start();
} on PlatformException {
await _voiceProcessor?.start(
_cheetah!.frameLength, _cheetah!.sampleRate);
} on PlatformException catch (e) {
throw CheetahRuntimeException(
"Audio engine failed to start. Hardware may not be supported.");
"Failed to start audio recording: ${e.message}");
}
} else {
throw CheetahRuntimeException(
Expand All @@ -112,20 +102,23 @@ class CheetahManager {
"Cannot start Cheetah - resources have already been released");
}

if (_voiceProcessor?.isRecording ?? false) {
await _voiceProcessor!.stop();
if (await _voiceProcessor?.isRecording() ?? false) {
try {
await _voiceProcessor?.stop();
} on PlatformException catch (e) {
throw CheetahRuntimeException(
"Failed to stop audio recording: ${e.message}");
}

CheetahTranscript cheetahTranscript = await _cheetah!.flush();
_transcriptCallback((cheetahTranscript.transcript) + " ");
}
}

Future<void> delete() async {
if (_voiceProcessor?.isRecording ?? false) {
await _voiceProcessor!.stop();
}
_removeVoiceProcessorListener?.call();
_removeErrorListener?.call();
await stopProcess();
_voiceProcessor = null;

_cheetah?.delete();
_cheetah = null;
}
Expand Down
6 changes: 3 additions & 3 deletions demo/flutter/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright 2022 Picovoice Inc.
// Copyright 2022-2023 Picovoice Inc.
//
// You may not use this file except in compliance with the license. A copy of the license is located in the "LICENSE"
// file accompanying this source.
Expand Down Expand Up @@ -113,7 +113,7 @@ class _MyAppState extends State<MyApp> {
isProcessing = true;
});
} on CheetahException catch (ex) {
print("Failed to start audio capture: ${ex.message}");
errorCallback(ex);
}
}

Expand All @@ -128,7 +128,7 @@ class _MyAppState extends State<MyApp> {
isProcessing = false;
});
} on CheetahException catch (ex) {
print("Failed to start audio capture: ${ex.message}");
errorCallback(ex);
}
}

Expand Down
29 changes: 18 additions & 11 deletions demo/flutter/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ packages:
name: archive
url: "https://pub.dartlang.org"
source: hosted
version: "3.1.6"
version: "3.1.11"
async:
dependency: transitive
description:
Expand Down Expand Up @@ -56,7 +56,7 @@ packages:
name: collection
url: "https://pub.dartlang.org"
source: hosted
version: "1.15.0"
version: "1.16.0"
crypto:
dependency: transitive
description:
Expand All @@ -70,7 +70,7 @@ packages:
name: fake_async
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
version: "1.3.0"
ffi:
dependency: transitive
description:
Expand Down Expand Up @@ -106,7 +106,7 @@ packages:
name: flutter_voice_processor
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.7"
version: "1.1.0"
fuchsia_remote_debug_protocol:
dependency: transitive
description: flutter
Expand All @@ -131,6 +131,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.11"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.4"
meta:
dependency: transitive
description:
Expand All @@ -144,7 +151,7 @@ packages:
name: path
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0"
version: "1.8.1"
path_provider:
dependency: transitive
description:
Expand Down Expand Up @@ -200,7 +207,7 @@ packages:
name: platform
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.2"
version: "3.1.0"
plugin_platform_interface:
dependency: transitive
description:
Expand All @@ -226,7 +233,7 @@ packages:
name: source_span
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.1"
version: "1.8.2"
stack_trace:
dependency: transitive
description:
Expand Down Expand Up @@ -268,7 +275,7 @@ packages:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.3"
version: "0.4.9"
typed_data:
dependency: transitive
description:
Expand All @@ -282,14 +289,14 @@ packages:
name: vector_math
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.1"
version: "2.1.2"
vm_service:
dependency: transitive
description:
name: vm_service
url: "https://pub.dartlang.org"
source: hosted
version: "7.3.0"
version: "8.2.2"
webdriver:
dependency: transitive
description:
Expand All @@ -312,5 +319,5 @@ packages:
source: hosted
version: "0.2.0+1"
sdks:
dart: ">=2.15.0 <3.0.0"
dart: ">=2.17.0-0 <3.0.0"
flutter: ">=2.8.1"
Loading