Skip to content

Commit

Permalink
Add constructor fromPtr() for all flutter class with factory ctor. (#…
Browse files Browse the repository at this point in the history
…1667)

Co-authored-by: wangrui <[email protected]>
  • Loading branch information
w-rui and wangrui authored Dec 31, 2024
1 parent ebe92e5 commit 0a43e9c
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions flutter/sherpa_onnx/lib/src/audio_tagging.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ class AudioEvent {
}

class AudioTagging {
AudioTagging.fromPtr({required this.ptr, required this.config});

AudioTagging._({required this.ptr, required this.config});

// The user has to invoke AudioTagging.free() to avoid memory leak.
Expand Down
2 changes: 2 additions & 0 deletions flutter/sherpa_onnx/lib/src/keyword_spotter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ class KeywordResult {
}

class KeywordSpotter {
KeywordSpotter.fromPtr({required this.ptr, required this.config});

KeywordSpotter._({required this.ptr, required this.config});

/// The user is responsible to call the OnlineRecognizer.free()
Expand Down
2 changes: 2 additions & 0 deletions flutter/sherpa_onnx/lib/src/offline_recognizer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,8 @@ class OfflineRecognizerResult {
}

class OfflineRecognizer {
OfflineRecognizer.fromPtr({required this.ptr, required this.config});

OfflineRecognizer._({required this.ptr, required this.config});

void free() {
Expand Down
3 changes: 3 additions & 0 deletions flutter/sherpa_onnx/lib/src/offline_speaker_diarization.dart
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ class OfflineSpeakerDiarizationConfig {
}

class OfflineSpeakerDiarization {
OfflineSpeakerDiarization.fromPtr(
{required this.ptr, required this.config, required this.sampleRate});

OfflineSpeakerDiarization._(
{required this.ptr, required this.config, required this.sampleRate});

Expand Down
2 changes: 2 additions & 0 deletions flutter/sherpa_onnx/lib/src/online_recognizer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ class OnlineRecognizerResult {
}

class OnlineRecognizer {
OnlineRecognizer.fromPtr({required this.ptr, required this.config});

OnlineRecognizer._({required this.ptr, required this.config});

/// The user is responsible to call the OnlineRecognizer.free()
Expand Down
2 changes: 2 additions & 0 deletions flutter/sherpa_onnx/lib/src/punctuation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class OfflinePunctuationConfig {
}

class OfflinePunctuation {
OfflinePunctuation.fromPtr({required this.ptr, required this.config});

OfflinePunctuation._({required this.ptr, required this.config});

// The user has to invoke OfflinePunctuation.free() to avoid memory leak.
Expand Down
4 changes: 4 additions & 0 deletions flutter/sherpa_onnx/lib/src/speaker_identification.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class SpeakerEmbeddingExtractorConfig {
}

class SpeakerEmbeddingExtractor {
SpeakerEmbeddingExtractor.fromPtr({required this.ptr, required this.dim});

SpeakerEmbeddingExtractor._({required this.ptr, required this.dim});

/// The user is responsible to call the SpeakerEmbeddingExtractor.free()
Expand Down Expand Up @@ -101,6 +103,8 @@ class SpeakerEmbeddingExtractor {
}

class SpeakerEmbeddingManager {
SpeakerEmbeddingManager.fromPtr({required this.ptr, required this.dim});

SpeakerEmbeddingManager._({required this.ptr, required this.dim});

// The user has to use SpeakerEmbeddingManager.free() to avoid memory leak
Expand Down
2 changes: 2 additions & 0 deletions flutter/sherpa_onnx/lib/src/tts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ class GeneratedAudio {
}

class OfflineTts {
OfflineTts.fromPtr({required this.ptr, required this.config});

OfflineTts._({required this.ptr, required this.config});

/// The user is responsible to call the OfflineTts.free()
Expand Down
4 changes: 4 additions & 0 deletions flutter/sherpa_onnx/lib/src/vad.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ class SpeechSegment {
}

class CircularBuffer {
CircularBuffer.fromPtr({required this.ptr});

CircularBuffer._({required this.ptr});

/// The user has to invoke CircularBuffer.free() on the returned instance
Expand Down Expand Up @@ -115,6 +117,8 @@ class CircularBuffer {
}

class VoiceActivityDetector {
VoiceActivityDetector.fromPtr({required this.ptr, required this.config});

VoiceActivityDetector._({required this.ptr, required this.config});

// The user has to invoke VoiceActivityDetector.free() to avoid memory leak.
Expand Down

0 comments on commit 0a43e9c

Please sign in to comment.