Toggle navigation
Toggle navigation
此项目
正在载入...
Sign in
xuning
/
sherpaonnx
转到一个项目
Toggle navigation
项目
群组
代码片段
帮助
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
Fangjun Kuang
2025-01-29 21:34:39 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Committed by
GitHub
2025-01-29 21:34:39 +0800
Commit
884715187e4dea65ea2c8a2a7d91d10975f5c9bc
88471518
1 parent
f178e96b
Add ArkTS API for Keyword spotting. (#1775)
隐藏空白字符变更
内嵌
并排对比
正在显示
4 个修改的文件
包含
91 行增加
和
1 行删除
harmony-os/SherpaOnnxHar/sherpa_onnx/BuildProfile.ets
harmony-os/SherpaOnnxHar/sherpa_onnx/Index.ets
harmony-os/SherpaOnnxHar/sherpa_onnx/src/main/cpp/types/libsherpa_onnx/Index.d.ts
harmony-os/SherpaOnnxHar/sherpa_onnx/src/main/ets/components/KeywordSpotting.ets
harmony-os/SherpaOnnxHar/sherpa_onnx/BuildProfile.ets
查看文件 @
8847151
/**
* Use these variables when you tailor your ArkTS code. They must be of the const type.
*/
export const HAR_VERSION = '1.10.4
0
';
export const HAR_VERSION = '1.10.4
1
';
export const BUILD_MODE_NAME = 'debug';
export const DEBUG = true;
export const TARGET_NAME = 'default';
...
...
harmony-os/SherpaOnnxHar/sherpa_onnx/Index.ets
查看文件 @
8847151
...
...
@@ -53,3 +53,8 @@ export { OfflineSpeakerSegmentationPyannoteModelConfig,
OfflineSpeakerDiarization,
FastClusteringConfig,
} from './src/main/ets/components/NonStreamingSpeakerDiarization';
export { KeywordSpotterConfig,
KeywordSpotterResult,
KeywordSpotter,
} from './src/main/ets/components/KeywordSpotting';
...
...
harmony-os/SherpaOnnxHar/sherpa_onnx/src/main/cpp/types/libsherpa_onnx/Index.d.ts
查看文件 @
8847151
...
...
@@ -68,3 +68,10 @@ export const getOfflineSpeakerDiarizationSampleRate: (handle: object) => number;
export
const
offlineSpeakerDiarizationProcess
:
(
handle
:
object
,
input
:
object
)
=>
object
;
export
const
offlineSpeakerDiarizationProcessAsync
:
(
handle
:
object
,
input
:
object
,
callback
:
object
)
=>
object
;
export
const
offlineSpeakerDiarizationSetConfig
:
(
handle
:
object
,
config
:
object
)
=>
void
;
export
const
createKeywordSpotter
:
(
config
:
object
,
mgr
?:
object
)
=>
object
;
export
const
createKeywordStream
:
(
handle
:
object
,
keywords
?:
string
)
=>
object
;
export
const
isKeywordStreamReady
:
(
handle
:
object
,
stream
:
object
)
=>
boolean
;
export
const
decodeKeywordStream
:
(
handle
:
object
,
stream
:
object
)
=>
void
;
export
const
resetKeywordStream
:
(
handle
:
object
,
stream
:
object
)
=>
void
;
export
const
getKeywordResultAsJson
:
(
handle
:
object
,
stream
:
object
)
=>
string
;
...
...
harmony-os/SherpaOnnxHar/sherpa_onnx/src/main/ets/components/KeywordSpotting.ets
0 → 100644
查看文件 @
8847151
import {
createKeywordSpotter,
createKeywordStream,
isKeywordStreamReady,
decodeKeywordStream,
resetKeywordStream,
getKeywordResultAsJson,
} from 'libsherpa_onnx.so';
import { FeatureConfig } from './NonStreamingAsr';
import { OnlineModelConfig, OnlineStream } from './StreamingAsr';
export class KeywordSpotterConfig {
public featConfig: FeatureConfig = new FeatureConfig();
public modelConfig: OnlineModelConfig = new OnlineModelConfig();
public maxActivePaths: number = 4;
public numTrailingBlanks: number = 1;
public keywordsScore: number = 1;
public keywordsThreshold: number = 0.25;
public keywordsFile: string = '';
}
interface KeywordSpotterResultJson {
keyword: string;
timestamps: number[];
tokens: string[];
}
export class KeywordSpotterResult {
public keyword: string = '';
public tokens: string[] = [];
public timestamps: number[] = [];
public json: string = '';
}
export class KeywordSpotter {
public handle: object;
public config: KeywordSpotterConfig;
constructor(config: KeywordSpotterConfig, mgr?: object) {
this.handle = createKeywordSpotter(config, mgr);
this.config = config
}
createStream(keywords?: string): OnlineStream {
if (typeof keywords !== "undefined") {
return new OnlineStream(createKeywordStream(this.handle, keywords));
} else {
return new OnlineStream(createKeywordStream(this.handle));
}
}
isReady(stream: OnlineStream): boolean {
return isKeywordStreamReady(this.handle, stream.handle);
}
decode(stream: OnlineStream) {
decodeKeywordStream(this.handle, stream.handle);
}
reset(stream: OnlineStream) {
resetKeywordStream(this.handle, stream.handle);
}
getResult(stream: OnlineStream): KeywordSpotterResult {
const jsonStr: string = getKeywordResultAsJson(this.handle, stream.handle);
let o = JSON.parse(jsonStr) as KeywordSpotterResultJson;
const r = new KeywordSpotterResult()
r.keyword = o.keyword
r.timestamps = o.timestamps;
r.tokens = o.tokens;
r.json = jsonStr;
return r;
}
}
...
...
请
注册
或
登录
后发表评论