Commit e1876baa authored by Skye Yu's avatar Skye Yu

feat: Add real time transcribe API

parent d342b184
......@@ -22,16 +22,16 @@ export type BluetoothStatus = {
status: string;
mac?: string;
name?: string;
a2dp?:boolean;
hfp?:boolean;
avrcp?:boolean;
battery?:number;
}
a2dp?: boolean;
hfp?: boolean;
avrcp?: boolean;
battery?: number;
};
export type BluetoothDevice = {
name: string;
mac: string;
}
};
export const enum OS {
Windows = 'Windows',
......@@ -133,6 +133,11 @@ declare class Jensen {
connectBTDevice: (mac: string, seconds?: number) => Promise<ReturnStruct['common']>;
disconnectBTDevice: (seconds?: number) => Promise<ReturnStruct['common']>;
getBluetoothStatus: (seconds?: number) => Promise<BluetoothStatus>;
getRealtimeSettings: () => Promise<any>;
startRealtime: () => Promise<ReturnStruct['common']>;
pauseRealtime: () => Promise<ReturnStruct['common']>;
stopRealtime: () => Promise<ReturnStruct['common']>;
getRealtime: (frames: number) => Promise<string>;
}
export = Jensen;
......@@ -22,6 +22,10 @@ const SET_SETTINGS = 0x0c;
const GET_FILE_BLOCK = 0x0d;
const FACTORY_RESET = 0xf00b;
const REALTIME_READ_SETTING = 0x20;
const REALTIME_CONTROL = 0x21;
const REALTIME_TRANSFER = 0x22;
const BLUETOOTH_SCAN = 0x1001;
const BLUETOOTH_CMD = 0x1002;
const BLUETOOTH_STATUS = 0x1003;
......@@ -120,7 +124,14 @@ function Jensen(log) {
await device.selectConfiguration(1);
await device.claimInterface(0);
await device.selectAlternateInterface(0, 0);
self.model = device.productId == 0xB00C ? 'hidock-h1' : device.productId == 0xB00D ? 'hidock-h1e' : device.productId == 0xB00E ? 'hidock-p1' : 'unknown';
self.model =
device.productId == 0xb00c
? 'hidock-h1'
: device.productId == 0xb00d
? 'hidock-h1e'
: device.productId == 0xb00e
? 'hidock-p1'
: 'unknown';
} catch (e) {
Logger.error('jensen', 'setup', String(e));
}
......@@ -567,29 +578,29 @@ Jensen.prototype.restoreFactorySettings = async function (seconds) {
return this.send(new Command(RESTORE_FACTORY_SETTINGS).body([0x01, 0x02, 0x03, 0x04]), seconds);
};
Jensen.prototype.scanDevices = async function(seconds) {
Jensen.prototype.scanDevices = async function (seconds) {
if (this.model != 'hidock-p1') return null;
return this.send(new Command(BLUETOOTH_SCAN), seconds || 20);
}
};
Jensen.prototype.connectBTDevice = async function(mac, seconds) {
Jensen.prototype.connectBTDevice = async function (mac, seconds) {
if (this.model != 'hidock-p1') return null;
let marr = mac.split('-');
if (marr.length != 6) throw new Error('invalid mac');
let addr = [];
for (let i = 0; i < marr.length; i++) addr[i] = parseInt(marr[i], 16);
return this.send(new Command(BLUETOOTH_CMD).body([0x00].concat(addr)), seconds);
}
};
Jensen.prototype.disconnectBTDevice = async function(seconds) {
Jensen.prototype.disconnectBTDevice = async function (seconds) {
if (this.model != 'hidock-p1') return null;
return this.send(new Command(BLUETOOTH_CMD).body([0x01]), seconds);
}
};
Jensen.prototype.getBluetoothStatus = async function(seconds) {
Jensen.prototype.getBluetoothStatus = async function (seconds) {
if (this.model != 'hidock-p1') return null;
return this.send(new Command(BLUETOOTH_STATUS), seconds);
}
};
Jensen.prototype.listFiles = async function () {
let tag = 'filelist';
......@@ -660,19 +671,14 @@ Jensen.prototype.listFiles = async function () {
ftime = ftime.replace(/^(\d{2})?(\d{2})(\w{3})(\d{2})-(\d{2})(\d{2})(\d{2})-.*\.(hda|wav)$/gi, '20$2 $3 $4 $5:$6:$7');
ftime = new Date(ftime);
duration = (flen / 32) * 4;
}
else {
} else {
ftime = null;
}
if (ver == 1) {
duration = duration * 2;
}
else if (ver == 2)
{
} else if (ver == 2) {
duration = (flen - 44) / 48 / 2;
}
else if (ver == 3)
{
} else if (ver == 3) {
duration = (flen - 44) / 48 / 2 / 2;
}
let createDate = '';
......@@ -1014,6 +1020,42 @@ Jensen.prototype.sendScheduleInfo = function (infos) {
}
};
Jensen.prototype.getRealtimeSettings = async function () {
return this.send(new Command(REALTIME_READ_SETTING));
};
Jensen.prototype.startRealtime = async function () {
return this.send(new Command(REALTIME_CONTROL).body([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01]));
};
Jensen.prototype.pauseRealtime = async function () {
return this.send(new Command(REALTIME_CONTROL).body([0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01]));
};
Jensen.prototype.stopRealtime = async function () {
return this.send(new Command(REALTIME_CONTROL).body([0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01]));
};
Jensen.prototype.getRealtime = async function (frames) {
let a = (frames >> 24) & 0xff;
let b = (frames >> 16) & 0xff;
let c = (frames >> 8) & 0xff;
let d = (frames >> 0) & 0xff;
return this.send(new Command(REALTIME_TRANSFER).body([a, b, c, d]));
};
Jensen.registerHandler(REALTIME_CONTROL, commonMessageParser);
Jensen.registerHandler(REALTIME_READ_SETTING, (msg) => {
console.log(msg);
return msg;
});
Jensen.registerHandler(REALTIME_TRANSFER, (msg) => {
let a = msg.body[0] & 0xff;
let b = msg.body[1] & 0xff;
let c = msg.body[2] & 0xff;
let d = msg.body[3] & 0xff;
return {
rest: (a << 24) | (b << 16) | (c << 8) | d,
data: msg.body
};
});
Jensen.registerHandler(SET_DEVICE_TIME, commonMessageParser);
Jensen.registerHandler(BNC_DEMO_TEST, commonMessageParser);
Jensen.registerHandler(DELETE_FILE, (msg) => {
......@@ -1157,54 +1199,49 @@ Jensen.registerHandler(BLUETOOTH_SCAN, (msg) => {
let nums = ((msg.body[0] & 0xff) << 8) | (msg.body[1] & 0xff);
let devices = [];
let decoder = new TextDecoder('UTF-8');
for (let i = 0, k = 2; i < nums; i++)
{
for (let i = 0, k = 2; i < nums; i++) {
let len = ((msg.body[k++] & 0xff) << 8) | (msg.body[k++] & 0xff);
let sname = new Uint8Array(len);
for (let f = 0; f < len; f++)
{
for (let f = 0; f < len; f++) {
sname[f] = msg.body[k++] & 0xff;
}
let mac = [];
for (let f = 0; f < 6; f++)
{
let m = (msg.body[k++]).toString(16).toUpperCase();
for (let f = 0; f < 6; f++) {
let m = msg.body[k++].toString(16).toUpperCase();
mac.push(m.length == 1 ? '0' + m : m);
}
devices.push({
name : decoder.decode(sname),
mac : mac.join('-')
name: decoder.decode(sname),
mac: mac.join('-')
});
}
return devices;
});
Jensen.registerHandler(BLUETOOTH_STATUS, (msg) => {
if (msg.body.length == 0) return { status : 'disconnected' };
if (msg.body.length == 0) return { status: 'disconnected' };
let status = msg.body[0];
if (status == 1) return { status : 'disconnected' };
if (status == 1) return { status: 'disconnected' };
let flen = ((msg.body[1] & 0xff) << 8) | (msg.body[2] & 0xff);
let decoder = new TextDecoder('UTF-8');
let sname = new Uint8Array(flen);
let i = 3;
for (let k = 0; i < msg.body.length && k < flen; i++, k++)
{
for (let k = 0; i < msg.body.length && k < flen; i++, k++) {
sname[k] = msg.body[i] & 0xff;
}
let mac = [];
for (let k = 0; i < msg.body.length && k < 6; k++)
{
let m = (msg.body[i++]).toString(16).toUpperCase();
mac.push(m.length == 1 ? '0' + m : m);
for (let k = 0; i < msg.body.length && k < 6; k++) {
let m = msg.body[i++].toString(16).toUpperCase();
mac.push(m.length == 1 ? '0' + m : m);
}
return {
status : 'connected',
mac : mac.join('-'),
name : decoder.decode(sname),
a2dp : (msg.body[i++] & 0xff) == 1,
hfp : (msg.body[i++] & 0xff) == 1,
avrcp : (msg.body[i++] & 0xff) == 1,
battery : parseInt((msg.body[i++] & 0xff) / 255 * 100)
status: 'connected',
mac: mac.join('-'),
name: decoder.decode(sname),
a2dp: (msg.body[i++] & 0xff) == 1,
hfp: (msg.body[i++] & 0xff) == 1,
avrcp: (msg.body[i++] & 0xff) == 1,
battery: parseInt(((msg.body[i++] & 0xff) / 255) * 100)
};
});
......@@ -1216,5 +1253,4 @@ Jensen.registerHandler(TEST_SN_WRITE, commonMessageParser);
Jensen.registerHandler(SCHEDULE_INFO, commonMessageParser);
Jensen.registerHandler(BLUETOOTH_CMD, commonMessageParser);
export { Jensen };
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment