npm i --save @vocale/mdk
- 版本:0.1.0
- GitHub:
- NPM: https://npmjs.net.cn/package/%40vocale%2Fmdk
- 下载量
- 昨日: 0
- 上周: 13
- 上月: 31
权限
iOS
如果您要使用录音功能,需要在 iOS 上授予设备访问麦克风的权限。如果不这样做,您的应用程序可能在设备上崩溃,或者您的应用程序可能在苹果的审查过程中被拒绝。为此,请将以下键添加到您的 app/App_Resources/iOS/Info.plist
文件中
<key>NSMicrophoneUsageDescription</key>
<string>Recording Practice Sessions</string>
Android
如果您打算在 Android 上使用录音功能,需要在 App_Resources 中的 AndroidManifest.xml 文件中添加 RECORD_AUDIO 权限
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
MDK 配置
- 按照以下方式更新 MDKProject.json。我们需要包含 @klippa/nativescript-http 和 nativescript-audio,因为这些是必要的 peer dependendency NS 插件。
{
"Externals": ["@vocale/mdk", "@klippa/nativescript-http", "nativescript-audio"],
"NSPlugins": ["@klippa/nativescript-http@^3.0.4", "@vocale/mdk@latest"],
"NPMPlugins": ["nativescript-audio"],
}
使用方法
- 按照以下方式更新任何页面的 onLoaded 处理程序
import { Vocale } from '@vocale/mdk'
const vocale = new Vocale({
// Take these values from your Site's Dashboard in vocale.ai
siteId: "site-id",
apiKey: "api-key",
// Optional
// Use this if you want Vocale to internally trigger the clientAPI.showActivityIndicator()
// to display a loader while processing the audio
displayActivityIndicator: true // defaults to true
});
export default async function OnLoadedHandler(clientAPI) {
// your own code
// Add something like this
try {
/**
* Always set the client API first (page's context).
* You should set this before executing any other action on each page that uses Vocale
* so that it can parse the context and the form container
*/
vocale.setClientAPI(clientAPI);
/**
* Use sync form once the form has been loaded on the page
* so that Vocale can parse your form and uploaded the data to your dashboard
*/
await vocale.syncForm({ formId: "unique-form-id-string" })
} catch (error) {
// Handle errors here
}
}
- 在您的页面上创建一个按钮,并创建类似于这样的 "OnPress" 处理程序
import { Vocale } from '@vocale/mdk'
const vocale = new Vocale({
// Take these values from your Site's Dashboard in vocale.ai
siteId: "site-id",
apiKey: "api-key",
// Optional
// Use this if you want Vocale to internally trigger the clientAPI.showActivityIndicator()
// to display a loader while processing the audio
displayActivityIndicator: true // defaults to true
});
export default async function ButtonOnPressHandler(clientAPI) {
try {
/**
* Always set the client API first (page's context).
* You should set this before executing any other action on each page that uses Vocale
* so that it can parse the context and the form container
*/
vocale.setClientAPI(clientAPI);
if (vocale.isRecording) {
/**
* Stop the recording, send a payload to Vocale's AI service
* and attempts to fill the form with the parsed data.
*/
await vocale.stopRecording();
} else {
/**
* The formId must be the same as the one used on the OnLoaded handler.
* The user might be asked permissions to access their mic.
*/
await vocale.startRecording({ formId: "unique-form-id-string" }, onSuccessHandler, onErrorHandler)
}
} catch (error) {
// Handle errors here
}
}