-
Notifications
You must be signed in to change notification settings - Fork 444
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add speaker diarization API for HarmonyOS. (#1609)
- Loading branch information
1 parent
14944d8
commit 1bae408
Showing
18 changed files
with
279 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
...y-os/SherpaOnnxHar/sherpa_onnx/src/main/ets/components/NonStreamingSpeakerDiarization.ets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { | ||
createOfflineSpeakerDiarization, | ||
getOfflineSpeakerDiarizationSampleRate, | ||
offlineSpeakerDiarizationProcess, | ||
offlineSpeakerDiarizationSetConfig, | ||
} from 'libsherpa_onnx.so'; | ||
|
||
import { SpeakerEmbeddingExtractorConfig } from './SpeakerIdentification'; | ||
|
||
export class OfflineSpeakerSegmentationPyannoteModelConfig { | ||
public model: string = ''; | ||
} | ||
|
||
export class OfflineSpeakerSegmentationModelConfig { | ||
public pyannote: OfflineSpeakerSegmentationPyannoteModelConfig = new OfflineSpeakerSegmentationPyannoteModelConfig(); | ||
public numThreads: number = 1; | ||
public debug: boolean = false; | ||
public provider: string = 'cpu'; | ||
} | ||
|
||
export class FastClusteringConfig { | ||
public numClusters: number = -1; | ||
public threshold: number = 0.5; | ||
} | ||
|
||
export class OfflineSpeakerDiarizationConfig { | ||
public segmentation: OfflineSpeakerSegmentationModelConfig = new OfflineSpeakerSegmentationModelConfig(); | ||
public embedding: SpeakerEmbeddingExtractorConfig = new SpeakerEmbeddingExtractorConfig(); | ||
public clustering: FastClusteringConfig = new FastClusteringConfig(); | ||
public minDurationOn: number = 0.2; | ||
public minDurationOff: number = 0.5; | ||
} | ||
|
||
export class OfflineSpeakerDiarizationSegment { | ||
public start: number = 0; // in secondspublic end: number = 0; // in secondspublic speaker: number = | ||
0; // ID of the speaker; count from 0 | ||
} | ||
|
||
export class OfflineSpeakerDiarization { | ||
public config: OfflineSpeakerDiarizationConfig; | ||
public sampleRate: number; | ||
private handle: object; | ||
|
||
constructor(config: OfflineSpeakerDiarizationConfig, mgr?: object) { | ||
this.handle = createOfflineSpeakerDiarization(config, mgr); | ||
this.config = config; | ||
|
||
this.sampleRate = getOfflineSpeakerDiarizationSampleRate(this.handle); | ||
} | ||
|
||
/** | ||
* samples is a 1-d float32 array. Each element of the array should be | ||
* in the range [-1, 1]. | ||
* | ||
* We assume its sample rate equals to this.sampleRate. | ||
* | ||
* Returns an array of object, where an object is | ||
* | ||
* { | ||
* "start": start_time_in_seconds, | ||
* "end": end_time_in_seconds, | ||
* "speaker": an_integer, | ||
* } | ||
*/ | ||
process(samples: Float32Array): OfflineSpeakerDiarizationSegment { | ||
return offlineSpeakerDiarizationProcess(this.handle, samples) as OfflineSpeakerDiarizationSegment; | ||
} | ||
|
||
setConfig(config: OfflineSpeakerDiarizationConfig) { | ||
offlineSpeakerDiarizationSetConfig(this.handle, config); | ||
this.config.clustering = config.clustering; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.