mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-11-28 04:59:52 +01:00
feat: asr integration && test_page audio process
This commit is contained in:
parent
43cb9f7a8a
commit
8b4f197b31
2 changed files with 14 additions and 3 deletions
|
|
@ -45,16 +45,16 @@ class ASRProvider(ASRProviderBase):
|
||||||
with open(file_path, "rb") as audio_file: # with open to ensure file is closed
|
with open(file_path, "rb") as audio_file: # with open to ensure file is closed
|
||||||
|
|
||||||
start_time = time.time()
|
start_time = time.time()
|
||||||
transcription: Transcription = self._client.audio.transcriptions.create(
|
transcription: str = self._client.audio.transcriptions.create(
|
||||||
model=self.model,
|
model=self.model,
|
||||||
file=audio_file,
|
file=audio_file,
|
||||||
response_format="text"
|
response_format="text"
|
||||||
)
|
)
|
||||||
logger.bind(tag=TAG).debug(
|
logger.bind(tag=TAG).debug(
|
||||||
f"Audio transcription latency: {time.time() - start_time:.3f}s | Result: {transcription.text}"
|
f"Audio transcription latency: {time.time() - start_time:.3f}s | Result: {transcription}"
|
||||||
)
|
)
|
||||||
|
|
||||||
return transcription.text, file_path
|
return transcription, file_path
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.bind(tag=TAG).error(f"Audio transcription failed: {e}")
|
logger.bind(tag=TAG).error(f"Audio transcription failed: {e}")
|
||||||
|
|
|
||||||
|
|
@ -1430,6 +1430,12 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
log('使用AudioWorklet处理音频', 'success');
|
log('使用AudioWorklet处理音频', 'success');
|
||||||
|
// 需要连接输出,否则不会触发处理
|
||||||
|
// 我们创建一个静音通道
|
||||||
|
const silent = audioContext.createGain();
|
||||||
|
silent.gain.value = 0;
|
||||||
|
audioProcessor.connect(silent);
|
||||||
|
silent.connect(audioContext.destination);
|
||||||
return { node: audioProcessor, type: 'worklet' };
|
return { node: audioProcessor, type: 'worklet' };
|
||||||
} else {
|
} else {
|
||||||
// 使用旧版ScriptProcessorNode作为回退方案
|
// 使用旧版ScriptProcessorNode作为回退方案
|
||||||
|
|
@ -1604,6 +1610,11 @@
|
||||||
// 创建音频上下文和分析器
|
// 创建音频上下文和分析器
|
||||||
audioContext = getAudioContextInstance();
|
audioContext = getAudioContextInstance();
|
||||||
|
|
||||||
|
// 浏览器出于安全和性能考虑,新创建的 AudioContext 默认处于 suspended 状态,必须显式调用 resume() 才会开始处理音频。
|
||||||
|
if (audioContext.state === 'suspended') {
|
||||||
|
await audioContext.resume();
|
||||||
|
}
|
||||||
|
|
||||||
// 创建音频处理器
|
// 创建音频处理器
|
||||||
const processorResult = await createAudioProcessor();
|
const processorResult = await createAudioProcessor();
|
||||||
if (!processorResult) {
|
if (!processorResult) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue