JLBA202505130001_关于吉林银行新建AI智能培训系统的需求_继续开发语音按钮

This commit is contained in:
田岩
2026-03-03 17:58:22 +08:00
parent d307b6b6d7
commit 60e7f272d8
18 changed files with 385 additions and 223 deletions
@@ -1,3 +1,3 @@
{
"minSdkVersion": "21"
"minSdkVersion": "35"
}
@@ -22,7 +22,8 @@ const minBufferSize = AudioRecord.getMinBufferSize(sampleRate, channelConfig, au
const bufferSize = minBufferSize * 2;
let audioRecord : AudioRecord | null = null;
let recordThread : Thread | null = null;
// 新增:录音启动时间戳(毫秒)
let recordStartTime: number | null = null;
// ========== 2. 对外暴露的便捷方法(符合UTS导出规范) ==========
@UTSJS.keepAlive
export function startAudioRecord(options : StartAudioRecordOptions) : void {
@@ -43,9 +44,12 @@ export function startAudioRecord(options : StartAudioRecordOptions) : void {
isRecording.set(true)
const _recordThread = new Thread(() => {
_audioRecord.startRecording(); // 开始采集
const recordId = `${new Date().getTime()}_${Math.floor(Math.random() * 10000)}`;
recordStartTime = new Date().getTime();
options.onStart?.({
startTime:1111111
startTime: recordStartTime as number,
sampleRate:sampleRate as number,
recordId: recordId
} as AudioStartRes);
console.log('AudioRecord已启动采集');
const buffer = new ByteArray(bufferSize); // 缓冲区只创建一次,避免重复分配内存
@@ -96,5 +100,4 @@ export function stopAudioRecord() : void {
}
}
}
export function preRequestRecordPermission(callback?: (granted: boolean) => void) {}
export function preRequestRecordPermission(callback ?: (granted : boolean) => void) { callback?.(true); }
@@ -125,7 +125,7 @@ export function startAudioRecord(options: StartAudioRecordOptions): void {
console.log("硬件原生格式:", inputFormat.commonFormat);
recordStartTime = new Date().getTime();
// 1. 生成录音唯一标识(UUID,方便多录音实例管理)
const recordId = `${new Date().getTime()}-${Math.floor(Math.random() * 10000)}`;
const recordId = `${new Date().getTime()}_${Math.floor(Math.random() * 10000)}`;
options.onStart?.({
recordId: recordId, // 唯一标识
sampleRate: inputFormat.sampleRate, // 采样率
@@ -6,7 +6,7 @@
// 成功开启录音的回调参数:返回录音基础配置
export type AudioStartRes = {
recordId ?: string; // 录音唯一标识(方便多录音实例管理)
recordId : string; // 录音唯一标识(方便多录音实例管理)
sampleRate ?: number; // 采样率(如16000
startTime : number; // 开启时间戳(毫秒)
};