Online demo https://pingxingyun.github.io/vh-webclient/ CloudApp unity3d_demo
- install nodejs v15.14.0
- install yarn
- yarn
npm install -g yarn
Terminal cd to project root dir and run:
yarn install
yarn serve
App running at:
- Local: http://localhost:8080/
- Network: http://192.168.0.161:8080/
Browser Open http://localhost:8080/
Browser request https or localhost to enable audio recoder.
yarn build
Open App.vue find line 237, change serverAddress, appliId. LarkSR cloud appid from LarkSR admin server.
const larksr = new LarkSR({
rootElement: this.$refs["appContainer"],
// serverAddress: "http://cloudlark.pingxingyun.com:8585",
serverAddress: "Lark Sever address",
// SDK auth code,connect business@pingxingyun.com or register https://www.pingxingyun.com/console/#/
authCode: "Your SDK ID",
// test backgroud url
// loadingBgUrl: "https://home-obs.pingxingyun.com/homePage_4_0/bg.jpg",
// logLevel: 'info',
});
larksr.connect({
// LarkSR cloud appid from LarkSR admin server.
// doc
// https://www.pingxingyun.com/online/api3_2.html?id=476
appliId: 'appid from LarkSR admin',
});
See src/App.vue
// Start audio recode and send to cloud.
this.larksr.startAiDmVoiceInput();
// Stop audio recode
this.larksr.stopAiDmVoiceInput();
this.larksr.aiDmTextInput("Your text");
larksr.on('aivoicestatus', (e) => {
console.log('aivoicestatus', e);
});
larksr.on('aivoiceasrresult', (e) => {
console.log('aivoiceasrresult', e.data);
});
larksr.on('aivoicedmresult', (e) => {
try {
let res = JSON.parse(e.data.text);
console.log('aivoicedmresult', res);
} catch(e) {
console.warn('parse aivoicedmresult failed', e.data);
}
});
larksr.on('aivoiceerror', (e) => {
alert(JSON.stringify(e.data));
});
CloudApp use LarkXRDataChannel64.dll to get AiVoice Data.
CloudApp get AiVoice result from LarXR.
Regis Aivoice callback.
LARKXR_API int DC_CALL lr_client_register_aivoice_callback(on_aivoice_callback cb,void* user_data);
Aivoice data struct.
struct AiVoicePacket
{
bool url; //true :online audio url(mp3) .false: audio pack (pcm)
unsigned int voice_id; //voice ID
const char* online_url; //if url = true url here or null
int url_size; //url size contain end \0
const char* nlg; // aivoice conversation text.
int nlg_size; // conversation text size, contain end \0
// if url=false, pcm package data here
unsigned int slice_id; // voice slice ID
int samples_per_sec; //eg.16000
int channels; //eg.1
const char* audio; //data ptr,if url = true null
int size_byte; //data byte size
bool last_packet; //is last package
};
typedef void(*on_aivoice_callback)(struct AiVoicePacket* packet,void* user_data);