-
Notifications
You must be signed in to change notification settings - Fork 445
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add microphone demo about VAD+ASR for HarmonyOS (#1581)
- Loading branch information
1 parent
299f239
commit c9d3b6c
Showing
7 changed files
with
276 additions
and
23 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
26 changes: 26 additions & 0 deletions
26
harmony-os/SherpaOnnxVadAsr/entry/src/main/ets/pages/Permission.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,26 @@ | ||
// This file is modified from | ||
// https://gitee.com/ukSir/hmchat2/blob/master/entry/src/main/ets/utils/permissionMananger.ets | ||
import { abilityAccessCtrl, bundleManager, common, Permissions } from '@kit.AbilityKit'; | ||
|
||
export function allAllowed(permissions: Permissions[]): boolean { | ||
if (permissions.length == 0) { | ||
return false; | ||
} | ||
|
||
const mgr: abilityAccessCtrl.AtManager = abilityAccessCtrl.createAtManager(); | ||
|
||
const bundleInfo = bundleManager.getBundleInfoForSelfSync(bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION); | ||
|
||
let tokenID: number = bundleInfo.appInfo.accessTokenId; | ||
|
||
return permissions.every(permission => abilityAccessCtrl.GrantStatus.PERMISSION_GRANTED == | ||
mgr.checkAccessTokenSync(tokenID, permission)); | ||
} | ||
|
||
export async function requestPermissions(permissions: Permissions[]): Promise<boolean> { | ||
const mgr: abilityAccessCtrl.AtManager = abilityAccessCtrl.createAtManager(); | ||
const context: Context = getContext() as common.UIAbilityContext; | ||
|
||
const result = await mgr.requestPermissionsFromUser(context, permissions); | ||
return result.authResults.length > 0 && result.authResults.every(authResults => authResults == 0); | ||
} |
Oops, something went wrong.