Add VAD example for Dart API (#996)
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
// Copyright (c) 2024 Xiaomi Corporation
|
||||
import 'dart:convert';
|
||||
import 'dart:ffi';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:ffi/ffi.dart';
|
||||
|
||||
@@ -262,7 +261,7 @@ class OfflineRecognizer {
|
||||
final json =
|
||||
SherpaOnnxBindings.getOfflineStreamResultAsJson?.call(stream.ptr) ??
|
||||
nullptr;
|
||||
if (json == null) {
|
||||
if (json == nullptr) {
|
||||
return OfflineRecognizerResult(text: '', tokens: [], timestamps: []);
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ class OfflineStream {
|
||||
final pList = p.asTypedList(n);
|
||||
pList.setAll(0, samples);
|
||||
|
||||
SherpaOnnxBindings.acceptWaveformOffline?.call(this.ptr, sampleRate, p, n);
|
||||
SherpaOnnxBindings.acceptWaveformOffline?.call(ptr, sampleRate, p, n);
|
||||
|
||||
calloc.free(p);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
// Copyright (c) 2024 Xiaomi Corporation
|
||||
import 'dart:convert';
|
||||
import 'dart:ffi';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:ffi/ffi.dart';
|
||||
|
||||
@@ -247,7 +246,7 @@ class OnlineRecognizer {
|
||||
final json =
|
||||
SherpaOnnxBindings.getOnlineStreamResultAsJson?.call(ptr, stream.ptr) ??
|
||||
nullptr;
|
||||
if (json == null) {
|
||||
if (json == nullptr) {
|
||||
return OnlineRecognizerResult(text: '', tokens: [], timestamps: []);
|
||||
}
|
||||
|
||||
|
||||
@@ -28,8 +28,7 @@ class OnlineStream {
|
||||
final pList = p.asTypedList(n);
|
||||
pList.setAll(0, samples);
|
||||
|
||||
SherpaOnnxBindings.onlineStreamAcceptWaveform
|
||||
?.call(this.ptr, sampleRate, p, n);
|
||||
SherpaOnnxBindings.onlineStreamAcceptWaveform?.call(ptr, sampleRate, p, n);
|
||||
|
||||
calloc.free(p);
|
||||
}
|
||||
|
||||
@@ -553,13 +553,10 @@ typedef DestroyOnlineStreamNative = Void Function(
|
||||
typedef DestroyOnlineStream = void Function(Pointer<SherpaOnnxOnlineStream>);
|
||||
|
||||
typedef OnlineStreamAcceptWaveformNative = Void Function(
|
||||
Pointer<SherpaOnnxOnlineStream>,
|
||||
Int32 sample_rate,
|
||||
Pointer<Float>,
|
||||
Int32 n);
|
||||
Pointer<SherpaOnnxOnlineStream>, Int32, Pointer<Float>, Int32);
|
||||
|
||||
typedef OnlineStreamAcceptWaveform = void Function(
|
||||
Pointer<SherpaOnnxOnlineStream>, int sample_rate, Pointer<Float>, int n);
|
||||
Pointer<SherpaOnnxOnlineStream>, int, Pointer<Float>, int);
|
||||
|
||||
typedef OnlineStreamInputFinishedNative = Void Function(
|
||||
Pointer<SherpaOnnxOnlineStream>);
|
||||
|
||||
@@ -106,8 +106,8 @@ class CircularBuffer {
|
||||
SherpaOnnxBindings.circularBufferReset?.call(this.ptr);
|
||||
}
|
||||
|
||||
int get size => SherpaOnnxBindings.circularBufferSize?.call(this.ptr) ?? 0;
|
||||
int get head => SherpaOnnxBindings.circularBufferHead?.call(this.ptr) ?? 0;
|
||||
int get size => SherpaOnnxBindings.circularBufferSize?.call(ptr) ?? 0;
|
||||
int get head => SherpaOnnxBindings.circularBufferHead?.call(ptr) ?? 0;
|
||||
|
||||
Pointer<SherpaOnnxCircularBuffer> ptr;
|
||||
}
|
||||
@@ -159,38 +159,36 @@ class VoiceActivityDetector {
|
||||
final pList = p.asTypedList(n);
|
||||
pList.setAll(0, samples);
|
||||
|
||||
SherpaOnnxBindings.voiceActivityDetectorAcceptWaveform
|
||||
?.call(this.ptr, p, n);
|
||||
SherpaOnnxBindings.voiceActivityDetectorAcceptWaveform?.call(ptr, p, n);
|
||||
|
||||
calloc.free(p);
|
||||
}
|
||||
|
||||
bool isEmpty() {
|
||||
final int empty =
|
||||
SherpaOnnxBindings.voiceActivityDetectorEmpty?.call(this.ptr) ?? 0;
|
||||
SherpaOnnxBindings.voiceActivityDetectorEmpty?.call(ptr) ?? 0;
|
||||
|
||||
return empty == 1;
|
||||
}
|
||||
|
||||
bool isDetected() {
|
||||
final int detected =
|
||||
SherpaOnnxBindings.voiceActivityDetectorDetected?.call(this.ptr) ?? 0;
|
||||
SherpaOnnxBindings.voiceActivityDetectorDetected?.call(ptr) ?? 0;
|
||||
|
||||
return detected == 1;
|
||||
}
|
||||
|
||||
void pop() {
|
||||
SherpaOnnxBindings.voiceActivityDetectorPop?.call(this.ptr);
|
||||
SherpaOnnxBindings.voiceActivityDetectorPop?.call(ptr);
|
||||
}
|
||||
|
||||
void clear() {
|
||||
SherpaOnnxBindings.voiceActivityDetectorClear?.call(this.ptr);
|
||||
SherpaOnnxBindings.voiceActivityDetectorClear?.call(ptr);
|
||||
}
|
||||
|
||||
SpeechSegment front() {
|
||||
final Pointer<SherpaOnnxSpeechSegment> segment =
|
||||
SherpaOnnxBindings.voiceActivityDetectorFront?.call(this.ptr) ??
|
||||
nullptr;
|
||||
SherpaOnnxBindings.voiceActivityDetectorFront?.call(ptr) ?? nullptr;
|
||||
if (segment == nullptr) {
|
||||
return SpeechSegment(samples: Float32List(0), start: 0);
|
||||
}
|
||||
@@ -206,7 +204,7 @@ class VoiceActivityDetector {
|
||||
}
|
||||
|
||||
void reset() {
|
||||
SherpaOnnxBindings.voiceActivityDetectorReset?.call(this.ptr);
|
||||
SherpaOnnxBindings.voiceActivityDetectorReset?.call(ptr);
|
||||
}
|
||||
|
||||
Pointer<SherpaOnnxVoiceActivityDetector> ptr;
|
||||
|
||||
Reference in New Issue
Block a user