Skip to content

Commit

Permalink
flutter: add lang, emotion, event to OfflineRecognizerResult (#1268)
Browse files Browse the repository at this point in the history
  • Loading branch information
eschmidbauer authored Aug 16, 2024
1 parent 8880975 commit 8c087d9
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions flutter/sherpa_onnx/lib/src/offline_recognizer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -186,16 +186,24 @@ class OfflineRecognizerConfig {

class OfflineRecognizerResult {
OfflineRecognizerResult(
{required this.text, required this.tokens, required this.timestamps});
{required this.text,
required this.tokens,
required this.timestamps,
required this.lang,
required this.emotion,
required this.event});

@override
String toString() {
return 'OfflineRecognizerResult(text: $text, tokens: $tokens, timestamps: $timestamps)';
return 'OfflineRecognizerResult(text: $text, tokens: $tokens, timestamps: $timestamps, lang: $lang, emotion: $emotion, event: $event)';
}

final String text;
final List<String> tokens;
final List<double> timestamps;
final String lang;
final String emotion;
final String event;
}

class OfflineRecognizer {
Expand Down Expand Up @@ -319,7 +327,13 @@ class OfflineRecognizer {
SherpaOnnxBindings.getOfflineStreamResultAsJson?.call(stream.ptr) ??
nullptr;
if (json == nullptr) {
return OfflineRecognizerResult(text: '', tokens: [], timestamps: []);
return OfflineRecognizerResult(
text: '',
tokens: [],
timestamps: [],
lang: '',
emotion: '',
event: '');
}

final parsedJson = jsonDecode(toDartString(json));
Expand All @@ -329,7 +343,10 @@ class OfflineRecognizer {
return OfflineRecognizerResult(
text: parsedJson['text'],
tokens: List<String>.from(parsedJson['tokens']),
timestamps: List<double>.from(parsedJson['timestamps']));
timestamps: List<double>.from(parsedJson['timestamps']),
lang: parsedJson['lang'],
emotion: parsedJson['emotion'],
event: parsedJson['event']);
}

Pointer<SherpaOnnxOfflineRecognizer> ptr;
Expand Down

0 comments on commit 8c087d9

Please sign in to comment.