mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-25 19:30:17 +08:00
添加了 TTS 相关服务并更新了设置
This commit is contained in:
parent
61570879ef
commit
7b9448f72e
123
asr-server/embedded.js
Normal file
123
asr-server/embedded.js
Normal file
@ -0,0 +1,123 @@
|
||||
/**
|
||||
* 内置的ASR服务器模块
|
||||
* 这个文件可以直接在Electron中运行,不需要外部依赖
|
||||
*/
|
||||
|
||||
// 使用Electron内置的Node.js模块
|
||||
const http = require('http')
|
||||
const path = require('path')
|
||||
const fs = require('fs')
|
||||
|
||||
// 输出环境信息
|
||||
console.log('ASR Server (Embedded) starting...')
|
||||
console.log('Node.js version:', process.version)
|
||||
console.log('Current directory:', __dirname)
|
||||
console.log('Current working directory:', process.cwd())
|
||||
console.log('Command line arguments:', process.argv)
|
||||
|
||||
// 创建HTTP服务器
|
||||
const server = http.createServer((req, res) => {
|
||||
try {
|
||||
if (req.url === '/' || req.url === '/index.html') {
|
||||
// 尝试多个可能的路径
|
||||
const possiblePaths = [
|
||||
// 当前目录
|
||||
path.join(__dirname, 'index.html'),
|
||||
// 上级目录
|
||||
path.join(__dirname, '..', 'index.html'),
|
||||
// 应用根目录
|
||||
path.join(process.cwd(), 'index.html')
|
||||
]
|
||||
|
||||
console.log('Possible index.html paths:', possiblePaths)
|
||||
|
||||
// 查找第一个存在的文件
|
||||
let indexPath = null
|
||||
for (const p of possiblePaths) {
|
||||
try {
|
||||
if (fs.existsSync(p)) {
|
||||
indexPath = p
|
||||
console.log(`Found index.html at: ${p}`)
|
||||
break
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(`Error checking existence of ${p}:`, e)
|
||||
}
|
||||
}
|
||||
|
||||
if (indexPath) {
|
||||
// 读取文件内容并发送
|
||||
fs.readFile(indexPath, (err, data) => {
|
||||
if (err) {
|
||||
console.error('Error reading index.html:', err)
|
||||
res.writeHead(500)
|
||||
res.end('Error reading index.html')
|
||||
return
|
||||
}
|
||||
|
||||
res.writeHead(200, { 'Content-Type': 'text/html' })
|
||||
res.end(data)
|
||||
})
|
||||
} else {
|
||||
// 如果找不到文件,返回一个简单的HTML页面
|
||||
console.error('Could not find index.html, serving fallback page')
|
||||
res.writeHead(200, { 'Content-Type': 'text/html' })
|
||||
res.end(`
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>ASR Server</title>
|
||||
<style>
|
||||
body { font-family: sans-serif; padding: 2em; }
|
||||
h1 { color: #333; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>ASR Server is running</h1>
|
||||
<p>This is a fallback page because the index.html file could not be found.</p>
|
||||
<p>Server is running at: http://localhost:34515</p>
|
||||
<p>Current directory: ${__dirname}</p>
|
||||
<p>Working directory: ${process.cwd()}</p>
|
||||
</body>
|
||||
</html>
|
||||
`)
|
||||
}
|
||||
} else {
|
||||
// 处理其他请求
|
||||
res.writeHead(404)
|
||||
res.end('Not found')
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error handling request:', error)
|
||||
res.writeHead(500)
|
||||
res.end('Server error')
|
||||
}
|
||||
})
|
||||
|
||||
// 添加进程错误处理
|
||||
process.on('uncaughtException', (error) => {
|
||||
console.error('[Server] Uncaught exception:', error)
|
||||
// 不立即退出,给日志输出的时间
|
||||
setTimeout(() => process.exit(1), 1000)
|
||||
})
|
||||
|
||||
process.on('unhandledRejection', (reason, promise) => {
|
||||
console.error('[Server] Unhandled rejection at:', promise, 'reason:', reason)
|
||||
})
|
||||
|
||||
// 尝试启动服务器
|
||||
try {
|
||||
const port = 34515
|
||||
server.listen(port, () => {
|
||||
console.log(`[Server] Server running at http://localhost:${port}`)
|
||||
})
|
||||
|
||||
// 处理服务器错误
|
||||
server.on('error', (error) => {
|
||||
console.error(`[Server] Failed to start server:`, error)
|
||||
process.exit(1) // Exit if server fails to start
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('[Server] Critical error starting server:', error)
|
||||
process.exit(1)
|
||||
}
|
||||
425
asr-server/index.html
Normal file
425
asr-server/index.html
Normal file
@ -0,0 +1,425 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Cherry Studio ASR</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: sans-serif;
|
||||
padding: 1em;
|
||||
}
|
||||
|
||||
#status {
|
||||
margin-top: 1em;
|
||||
font-style: italic;
|
||||
color: #555;
|
||||
}
|
||||
|
||||
#result {
|
||||
margin-top: 0.5em;
|
||||
border: 1px solid #ccc;
|
||||
padding: 0.5em;
|
||||
min-height: 50px;
|
||||
background: #f9f9f9;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>浏览器语音识别中继页面</h1>
|
||||
<p>这个页面需要在浏览器中保持打开,以便应用使用其语音识别功能。</p>
|
||||
<div id="status">正在连接到服务器...</div>
|
||||
<div id="result"></div>
|
||||
|
||||
<script>
|
||||
const statusDiv = document.getElementById('status');
|
||||
const resultDiv = document.getElementById('result');
|
||||
// 尝试连接到WebSocket服务器
|
||||
let ws;
|
||||
let reconnectAttempts = 0;
|
||||
const maxReconnectAttempts = 5;
|
||||
const reconnectInterval = 2000; // 2秒
|
||||
|
||||
function connectWebSocket() {
|
||||
try {
|
||||
ws = new WebSocket('ws://localhost:34515');
|
||||
|
||||
ws.onopen = () => {
|
||||
reconnectAttempts = 0;
|
||||
updateStatus('已连接到服务器,等待指令...');
|
||||
ws.send(JSON.stringify({ type: 'identify', role: 'browser' }));
|
||||
};
|
||||
|
||||
ws.onmessage = handleMessage;
|
||||
|
||||
ws.onerror = (error) => {
|
||||
console.error('[Browser Page] WebSocket Error:', error);
|
||||
updateStatus('WebSocket 连接错误!请检查服务器是否运行。');
|
||||
};
|
||||
|
||||
ws.onclose = () => {
|
||||
console.log('[Browser Page] WebSocket Connection Closed');
|
||||
updateStatus('与服务器断开连接。尝试重新连接...');
|
||||
stopRecognition();
|
||||
|
||||
// 尝试重新连接
|
||||
if (reconnectAttempts < maxReconnectAttempts) {
|
||||
reconnectAttempts++;
|
||||
updateStatus(`与服务器断开连接。尝试重新连接 (${reconnectAttempts}/${maxReconnectAttempts})...`);
|
||||
setTimeout(connectWebSocket, reconnectInterval);
|
||||
} else {
|
||||
updateStatus('无法连接到服务器。请刷新页面或重启应用。');
|
||||
}
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('[Browser Page] Error creating WebSocket:', error);
|
||||
updateStatus('创建WebSocket连接时出错。请刷新页面或重启应用。');
|
||||
}
|
||||
}
|
||||
|
||||
// 初始连接
|
||||
connectWebSocket();
|
||||
let recognition = null;
|
||||
const SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
|
||||
|
||||
function updateStatus(message) {
|
||||
console.log(`[Browser Page Status] ${message}`);
|
||||
statusDiv.textContent = message;
|
||||
}
|
||||
|
||||
function handleMessage(event) {
|
||||
let data;
|
||||
try {
|
||||
data = JSON.parse(event.data);
|
||||
console.log('[Browser Page] Received command:', data);
|
||||
} catch (e) {
|
||||
console.error('[Browser Page] Received non-JSON message:', event.data);
|
||||
return;
|
||||
}
|
||||
|
||||
if (data.type === 'start') {
|
||||
startRecognition();
|
||||
} else if (data.type === 'stop') {
|
||||
stopRecognition();
|
||||
} else if (data.type === 'reset') {
|
||||
// 强制重置语音识别
|
||||
forceResetRecognition();
|
||||
} else {
|
||||
console.warn('[Browser Page] Received unknown command type:', data.type);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
function setupRecognition() {
|
||||
if (!SpeechRecognition) {
|
||||
updateStatus('错误:此浏览器不支持 Web Speech API。');
|
||||
return false;
|
||||
}
|
||||
if (recognition && recognition.recognizing) {
|
||||
console.log('[Browser Page] Recognition already active.');
|
||||
return true;
|
||||
}
|
||||
|
||||
recognition = new SpeechRecognition();
|
||||
recognition.lang = 'zh-CN';
|
||||
recognition.continuous = true;
|
||||
recognition.interimResults = true;
|
||||
// 增加以下设置提高语音识别的可靠性
|
||||
recognition.maxAlternatives = 3; // 返回多个可能的识别结果
|
||||
// 设置较短的语音识别时间,使用户能更快地看到结果
|
||||
// 注意:这个属性不是标准的,可能不是所有浏览器都支持
|
||||
try {
|
||||
// @ts-ignore
|
||||
recognition.audioStart = 0.1; // 尝试设置较低的起始音量阈值
|
||||
} catch (e) {
|
||||
console.log('[Browser Page] audioStart property not supported');
|
||||
}
|
||||
|
||||
recognition.onstart = () => {
|
||||
updateStatus("🎤 正在识别...");
|
||||
console.log('[Browser Page] SpeechRecognition started.');
|
||||
};
|
||||
|
||||
recognition.onresult = (event) => {
|
||||
console.log('[Browser Page] Recognition result event:', event);
|
||||
|
||||
let interim_transcript = '';
|
||||
let final_transcript = '';
|
||||
|
||||
// 输出识别结果的详细信息便于调试
|
||||
for (let i = event.resultIndex; i < event.results.length; ++i) {
|
||||
const confidence = event.results[i][0].confidence;
|
||||
console.log(`[Browser Page] Result ${i}: ${event.results[i][0].transcript} (Confidence: ${confidence.toFixed(2)})`);
|
||||
|
||||
if (event.results[i].isFinal) {
|
||||
final_transcript += event.results[i][0].transcript;
|
||||
} else {
|
||||
interim_transcript += event.results[i][0].transcript;
|
||||
}
|
||||
}
|
||||
|
||||
const resultText = final_transcript || interim_transcript;
|
||||
resultDiv.textContent = resultText;
|
||||
|
||||
// 更新状态显示
|
||||
if (resultText) {
|
||||
updateStatus(`🎤 正在识别... (已捕捉到语音)`);
|
||||
}
|
||||
|
||||
if (ws.readyState === WebSocket.OPEN) {
|
||||
console.log(`[Browser Page] Sending ${final_transcript ? 'final' : 'interim'} result to server:`, resultText);
|
||||
ws.send(JSON.stringify({ type: 'result', data: { text: resultText, isFinal: !!final_transcript } }));
|
||||
}
|
||||
};
|
||||
|
||||
recognition.onerror = (event) => {
|
||||
console.error(`[Browser Page] SpeechRecognition Error - Type: ${event.error}, Message: ${event.message}`);
|
||||
|
||||
// 根据错误类型提供更友好的错误提示
|
||||
let errorMessage = '';
|
||||
switch (event.error) {
|
||||
case 'no-speech':
|
||||
errorMessage = '未检测到语音,请确保麦克风工作正常并尝试说话。';
|
||||
// 尝试重新启动语音识别
|
||||
setTimeout(() => {
|
||||
if (recognition) {
|
||||
try {
|
||||
recognition.start();
|
||||
console.log('[Browser Page] Restarting recognition after no-speech error');
|
||||
} catch (e) {
|
||||
console.error('[Browser Page] Failed to restart recognition:', e);
|
||||
}
|
||||
}
|
||||
}, 1000);
|
||||
break;
|
||||
case 'audio-capture':
|
||||
errorMessage = '无法捕获音频,请确保麦克风已连接并已授权。';
|
||||
break;
|
||||
case 'not-allowed':
|
||||
errorMessage = '浏览器不允许使用麦克风,请检查权限设置。';
|
||||
break;
|
||||
case 'network':
|
||||
errorMessage = '网络错误导致语音识别失败。';
|
||||
break;
|
||||
case 'aborted':
|
||||
errorMessage = '语音识别被用户或系统中止。';
|
||||
break;
|
||||
default:
|
||||
errorMessage = `识别错误: ${event.error}`;
|
||||
}
|
||||
|
||||
updateStatus(`错误: ${errorMessage}`);
|
||||
|
||||
if (ws.readyState === WebSocket.OPEN) {
|
||||
ws.send(JSON.stringify({
|
||||
type: 'error',
|
||||
data: {
|
||||
error: event.error,
|
||||
message: errorMessage || event.message || `Recognition error: ${event.error}`
|
||||
}
|
||||
}));
|
||||
}
|
||||
};
|
||||
|
||||
recognition.onend = () => {
|
||||
console.log('[Browser Page] SpeechRecognition ended.');
|
||||
|
||||
// 检查是否是由于错误或用户手动停止导致的结束
|
||||
const isErrorOrStopped = statusDiv.textContent.includes('错误') || statusDiv.textContent.includes('停止');
|
||||
|
||||
if (!isErrorOrStopped) {
|
||||
// 如果不是由于错误或手动停止,则自动重新启动语音识别
|
||||
updateStatus("识别暂停,正在重新启动...");
|
||||
|
||||
// 保存当前的recognition对象
|
||||
const currentRecognition = recognition;
|
||||
|
||||
// 尝试重新启动语音识别
|
||||
setTimeout(() => {
|
||||
try {
|
||||
if (currentRecognition && currentRecognition === recognition) {
|
||||
currentRecognition.start();
|
||||
console.log('[Browser Page] Automatically restarting recognition');
|
||||
} else {
|
||||
// 如果recognition对象已经变化,重新创建一个
|
||||
setupRecognition();
|
||||
if (recognition) {
|
||||
recognition.start();
|
||||
console.log('[Browser Page] Created new recognition instance and started');
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('[Browser Page] Failed to restart recognition:', e);
|
||||
updateStatus("识别已停止。等待指令...");
|
||||
}
|
||||
}, 300);
|
||||
} else {
|
||||
updateStatus("识别已停止。等待指令...");
|
||||
|
||||
if (ws.readyState === WebSocket.OPEN) {
|
||||
ws.send(JSON.stringify({ type: 'status', message: 'stopped' }));
|
||||
}
|
||||
|
||||
// 只有在手动停止或错误时才重置recognition对象
|
||||
recognition = null;
|
||||
}
|
||||
};
|
||||
return true;
|
||||
}
|
||||
|
||||
function startRecognition() {
|
||||
if (!SpeechRecognition) {
|
||||
updateStatus('错误:浏览器不支持 Web Speech API。');
|
||||
return;
|
||||
}
|
||||
|
||||
// 显示正在准备的状态
|
||||
updateStatus('正在准备麦克风...');
|
||||
|
||||
if (recognition) {
|
||||
console.log('[Browser Page] Recognition already exists, stopping first.');
|
||||
stopRecognition();
|
||||
}
|
||||
|
||||
if (!setupRecognition()) return;
|
||||
|
||||
console.log('[Browser Page] Attempting to start recognition...');
|
||||
try {
|
||||
// 设置更长的超时时间,确保有足够的时间获取麦克风权限
|
||||
const micPermissionTimeout = setTimeout(() => {
|
||||
updateStatus('获取麦克风权限超时,请刷新页面重试。');
|
||||
}, 10000); // 10秒超时
|
||||
|
||||
navigator.mediaDevices.getUserMedia({
|
||||
audio: {
|
||||
echoCancellation: true,
|
||||
noiseSuppression: true,
|
||||
autoGainControl: true
|
||||
}
|
||||
})
|
||||
.then(stream => {
|
||||
clearTimeout(micPermissionTimeout);
|
||||
console.log('[Browser Page] Microphone access granted.');
|
||||
|
||||
// 检查麦克风音量级别
|
||||
const audioContext = new AudioContext();
|
||||
const analyser = audioContext.createAnalyser();
|
||||
const microphone = audioContext.createMediaStreamSource(stream);
|
||||
const javascriptNode = audioContext.createScriptProcessor(2048, 1, 1);
|
||||
|
||||
analyser.smoothingTimeConstant = 0.8;
|
||||
analyser.fftSize = 1024;
|
||||
|
||||
microphone.connect(analyser);
|
||||
analyser.connect(javascriptNode);
|
||||
javascriptNode.connect(audioContext.destination);
|
||||
|
||||
javascriptNode.onaudioprocess = function () {
|
||||
const array = new Uint8Array(analyser.frequencyBinCount);
|
||||
analyser.getByteFrequencyData(array);
|
||||
let values = 0;
|
||||
|
||||
const length = array.length;
|
||||
for (let i = 0; i < length; i++) {
|
||||
values += (array[i]);
|
||||
}
|
||||
|
||||
const average = values / length;
|
||||
console.log('[Browser Page] Microphone volume level:', average);
|
||||
|
||||
// 如果音量太低,显示提示
|
||||
if (average < 5) {
|
||||
updateStatus('麦克风音量很低,请说话或检查麦克风设置。');
|
||||
} else {
|
||||
updateStatus('🎤 正在识别...');
|
||||
}
|
||||
|
||||
// 只检查一次就断开连接
|
||||
microphone.disconnect();
|
||||
analyser.disconnect();
|
||||
javascriptNode.disconnect();
|
||||
};
|
||||
|
||||
// 释放测试用的音频流
|
||||
setTimeout(() => {
|
||||
stream.getTracks().forEach(track => track.stop());
|
||||
audioContext.close();
|
||||
}, 1000);
|
||||
|
||||
// 启动语音识别
|
||||
if (recognition) {
|
||||
recognition.start();
|
||||
updateStatus('🎤 正在识别...');
|
||||
} else {
|
||||
updateStatus('错误:Recognition 实例丢失。');
|
||||
console.error('[Browser Page] Recognition instance lost before start.');
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
clearTimeout(micPermissionTimeout);
|
||||
console.error('[Browser Page] Microphone access error:', err);
|
||||
|
||||
let errorMsg = `无法访问麦克风 (${err.name})`;
|
||||
if (err.name === 'NotAllowedError') {
|
||||
errorMsg = '麦克风访问被拒绝。请在浏览器设置中允许麦克风访问权限。';
|
||||
} else if (err.name === 'NotFoundError') {
|
||||
errorMsg = '未找到麦克风设备。请确保麦克风已连接。';
|
||||
}
|
||||
|
||||
updateStatus(`错误: ${errorMsg}`);
|
||||
recognition = null;
|
||||
});
|
||||
} catch (e) {
|
||||
console.error('[Browser Page] Error calling recognition.start():', e);
|
||||
updateStatus(`启动识别时出错: ${e.message}`);
|
||||
recognition = null;
|
||||
}
|
||||
}
|
||||
|
||||
function stopRecognition() {
|
||||
if (recognition) {
|
||||
console.log('[Browser Page] Stopping recognition...');
|
||||
updateStatus("正在停止识别...");
|
||||
try {
|
||||
recognition.stop();
|
||||
} catch (e) {
|
||||
console.error('[Browser Page] Error calling recognition.stop():', e);
|
||||
recognition = null;
|
||||
updateStatus("停止时出错,已强制重置。");
|
||||
}
|
||||
} else {
|
||||
console.log('[Browser Page] Recognition not active, nothing to stop.');
|
||||
updateStatus("识别未运行。");
|
||||
}
|
||||
}
|
||||
|
||||
function forceResetRecognition() {
|
||||
console.log('[Browser Page] Force resetting recognition...');
|
||||
updateStatus("强制重置语音识别...");
|
||||
|
||||
// 先尝试停止当前的识别
|
||||
if (recognition) {
|
||||
try {
|
||||
recognition.stop();
|
||||
} catch (e) {
|
||||
console.error('[Browser Page] Error stopping recognition during reset:', e);
|
||||
}
|
||||
}
|
||||
|
||||
// 强制设置为null,丢弃所有后续结果
|
||||
recognition = null;
|
||||
|
||||
// 通知服务器已重置
|
||||
if (ws.readyState === WebSocket.OPEN) {
|
||||
ws.send(JSON.stringify({ type: 'status', message: 'reset_complete' }));
|
||||
}
|
||||
|
||||
updateStatus("语音识别已重置,等待新指令。");
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
854
asr-server/package-lock.json
generated
Normal file
854
asr-server/package-lock.json
generated
Normal file
@ -0,0 +1,854 @@
|
||||
{
|
||||
"name": "cherry-asr-server",
|
||||
"version": "1.0.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "cherry-asr-server",
|
||||
"version": "1.0.0",
|
||||
"dependencies": {
|
||||
"express": "^4.18.2",
|
||||
"ws": "^8.13.0"
|
||||
}
|
||||
},
|
||||
"node_modules/accepts": {
|
||||
"version": "1.3.8",
|
||||
"resolved": "https://registry.npmmirror.com/accepts/-/accepts-1.3.8.tgz",
|
||||
"integrity": "sha512-PYAthTa2m2VKxuvSD3DPC/Gy+U+sOA1LAuT8mkmRuvw+NACSaeXEQ+NHcVF7rONl6qcaxV3Uuemwawk+7+SJLw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"mime-types": "~2.1.34",
|
||||
"negotiator": "0.6.3"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/array-flatten": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmmirror.com/array-flatten/-/array-flatten-1.1.1.tgz",
|
||||
"integrity": "sha512-PCVAQswWemu6UdxsDFFX/+gVeYqKAod3D3UVm91jHwynguOwAvYPhx8nNlM++NqRcK6CxxpUafjmhIdKiHibqg==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/body-parser": {
|
||||
"version": "1.20.3",
|
||||
"resolved": "https://registry.npmmirror.com/body-parser/-/body-parser-1.20.3.tgz",
|
||||
"integrity": "sha512-7rAxByjUMqQ3/bHJy7D6OGXvx/MMc4IqBn/X0fcM1QUcAItpZrBEYhWGem+tzXH90c+G01ypMcYJBO9Y30203g==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"bytes": "3.1.2",
|
||||
"content-type": "~1.0.5",
|
||||
"debug": "2.6.9",
|
||||
"depd": "2.0.0",
|
||||
"destroy": "1.2.0",
|
||||
"http-errors": "2.0.0",
|
||||
"iconv-lite": "0.4.24",
|
||||
"on-finished": "2.4.1",
|
||||
"qs": "6.13.0",
|
||||
"raw-body": "2.5.2",
|
||||
"type-is": "~1.6.18",
|
||||
"unpipe": "1.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.8",
|
||||
"npm": "1.2.8000 || >= 1.4.16"
|
||||
}
|
||||
},
|
||||
"node_modules/bytes": {
|
||||
"version": "3.1.2",
|
||||
"resolved": "https://registry.npmmirror.com/bytes/-/bytes-3.1.2.tgz",
|
||||
"integrity": "sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/call-bind-apply-helpers": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmmirror.com/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.2.tgz",
|
||||
"integrity": "sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"es-errors": "^1.3.0",
|
||||
"function-bind": "^1.1.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/call-bound": {
|
||||
"version": "1.0.4",
|
||||
"resolved": "https://registry.npmmirror.com/call-bound/-/call-bound-1.0.4.tgz",
|
||||
"integrity": "sha512-+ys997U96po4Kx/ABpBCqhA9EuxJaQWDQg7295H4hBphv3IZg0boBKuwYpt4YXp6MZ5AmZQnU/tyMTlRpaSejg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"call-bind-apply-helpers": "^1.0.2",
|
||||
"get-intrinsic": "^1.3.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/content-disposition": {
|
||||
"version": "0.5.4",
|
||||
"resolved": "https://registry.npmmirror.com/content-disposition/-/content-disposition-0.5.4.tgz",
|
||||
"integrity": "sha512-FveZTNuGw04cxlAiWbzi6zTAL/lhehaWbTtgluJh4/E95DqMwTmha3KZN1aAWA8cFIhHzMZUvLevkw5Rqk+tSQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"safe-buffer": "5.2.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/content-type": {
|
||||
"version": "1.0.5",
|
||||
"resolved": "https://registry.npmmirror.com/content-type/-/content-type-1.0.5.tgz",
|
||||
"integrity": "sha512-nTjqfcBFEipKdXCv4YDQWCfmcLZKm81ldF0pAopTvyrFGVbcR6P/VAAd5G7N+0tTr8QqiU0tFadD6FK4NtJwOA==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/cookie": {
|
||||
"version": "0.7.1",
|
||||
"resolved": "https://registry.npmmirror.com/cookie/-/cookie-0.7.1.tgz",
|
||||
"integrity": "sha512-6DnInpx7SJ2AK3+CTUE/ZM0vWTUboZCegxhC2xiIydHR9jNuTAASBrfEpHhiGOZw/nX51bHt6YQl8jsGo4y/0w==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/cookie-signature": {
|
||||
"version": "1.0.6",
|
||||
"resolved": "https://registry.npmmirror.com/cookie-signature/-/cookie-signature-1.0.6.tgz",
|
||||
"integrity": "sha512-QADzlaHc8icV8I7vbaJXJwod9HWYp8uCqf1xa4OfNu1T7JVxQIrUgOWtHdNDtPiywmFbiS12VjotIXLrKM3orQ==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/debug": {
|
||||
"version": "2.6.9",
|
||||
"resolved": "https://registry.npmmirror.com/debug/-/debug-2.6.9.tgz",
|
||||
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"ms": "2.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/depd": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmmirror.com/depd/-/depd-2.0.0.tgz",
|
||||
"integrity": "sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/destroy": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmmirror.com/destroy/-/destroy-1.2.0.tgz",
|
||||
"integrity": "sha512-2sJGJTaXIIaR1w4iJSNoN0hnMY7Gpc/n8D4qSCJw8QqFWXf7cuAgnEHxBpweaVcPevC2l3KpjYCx3NypQQgaJg==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.8",
|
||||
"npm": "1.2.8000 || >= 1.4.16"
|
||||
}
|
||||
},
|
||||
"node_modules/dunder-proto": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmmirror.com/dunder-proto/-/dunder-proto-1.0.1.tgz",
|
||||
"integrity": "sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"call-bind-apply-helpers": "^1.0.1",
|
||||
"es-errors": "^1.3.0",
|
||||
"gopd": "^1.2.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/ee-first": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmmirror.com/ee-first/-/ee-first-1.1.1.tgz",
|
||||
"integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/encodeurl": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmmirror.com/encodeurl/-/encodeurl-2.0.0.tgz",
|
||||
"integrity": "sha512-Q0n9HRi4m6JuGIV1eFlmvJB7ZEVxu93IrMyiMsGC0lrMJMWzRgx6WGquyfQgZVb31vhGgXnfmPNNXmxnOkRBrg==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/es-define-property": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmmirror.com/es-define-property/-/es-define-property-1.0.1.tgz",
|
||||
"integrity": "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/es-errors": {
|
||||
"version": "1.3.0",
|
||||
"resolved": "https://registry.npmmirror.com/es-errors/-/es-errors-1.3.0.tgz",
|
||||
"integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/es-object-atoms": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmmirror.com/es-object-atoms/-/es-object-atoms-1.1.1.tgz",
|
||||
"integrity": "sha512-FGgH2h8zKNim9ljj7dankFPcICIK9Cp5bm+c2gQSYePhpaG5+esrLODihIorn+Pe6FGJzWhXQotPv73jTaldXA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"es-errors": "^1.3.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/escape-html": {
|
||||
"version": "1.0.3",
|
||||
"resolved": "https://registry.npmmirror.com/escape-html/-/escape-html-1.0.3.tgz",
|
||||
"integrity": "sha512-NiSupZ4OeuGwr68lGIeym/ksIZMJodUGOSCZ/FSnTxcrekbvqrgdUxlJOMpijaKZVjAJrWrGs/6Jy8OMuyj9ow==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/etag": {
|
||||
"version": "1.8.1",
|
||||
"resolved": "https://registry.npmmirror.com/etag/-/etag-1.8.1.tgz",
|
||||
"integrity": "sha512-aIL5Fx7mawVa300al2BnEE4iNvo1qETxLrPI/o05L7z6go7fCw1J6EQmbK4FmJ2AS7kgVF/KEZWufBfdClMcPg==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/express": {
|
||||
"version": "4.21.2",
|
||||
"resolved": "https://registry.npmmirror.com/express/-/express-4.21.2.tgz",
|
||||
"integrity": "sha512-28HqgMZAmih1Czt9ny7qr6ek2qddF4FclbMzwhCREB6OFfH+rXAnuNCwo1/wFvrtbgsQDb4kSbX9de9lFbrXnA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"accepts": "~1.3.8",
|
||||
"array-flatten": "1.1.1",
|
||||
"body-parser": "1.20.3",
|
||||
"content-disposition": "0.5.4",
|
||||
"content-type": "~1.0.4",
|
||||
"cookie": "0.7.1",
|
||||
"cookie-signature": "1.0.6",
|
||||
"debug": "2.6.9",
|
||||
"depd": "2.0.0",
|
||||
"encodeurl": "~2.0.0",
|
||||
"escape-html": "~1.0.3",
|
||||
"etag": "~1.8.1",
|
||||
"finalhandler": "1.3.1",
|
||||
"fresh": "0.5.2",
|
||||
"http-errors": "2.0.0",
|
||||
"merge-descriptors": "1.0.3",
|
||||
"methods": "~1.1.2",
|
||||
"on-finished": "2.4.1",
|
||||
"parseurl": "~1.3.3",
|
||||
"path-to-regexp": "0.1.12",
|
||||
"proxy-addr": "~2.0.7",
|
||||
"qs": "6.13.0",
|
||||
"range-parser": "~1.2.1",
|
||||
"safe-buffer": "5.2.1",
|
||||
"send": "0.19.0",
|
||||
"serve-static": "1.16.2",
|
||||
"setprototypeof": "1.2.0",
|
||||
"statuses": "2.0.1",
|
||||
"type-is": "~1.6.18",
|
||||
"utils-merge": "1.0.1",
|
||||
"vary": "~1.1.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.10.0"
|
||||
},
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/express"
|
||||
}
|
||||
},
|
||||
"node_modules/finalhandler": {
|
||||
"version": "1.3.1",
|
||||
"resolved": "https://registry.npmmirror.com/finalhandler/-/finalhandler-1.3.1.tgz",
|
||||
"integrity": "sha512-6BN9trH7bp3qvnrRyzsBz+g3lZxTNZTbVO2EV1CS0WIcDbawYVdYvGflME/9QP0h0pYlCDBCTjYa9nZzMDpyxQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"debug": "2.6.9",
|
||||
"encodeurl": "~2.0.0",
|
||||
"escape-html": "~1.0.3",
|
||||
"on-finished": "2.4.1",
|
||||
"parseurl": "~1.3.3",
|
||||
"statuses": "2.0.1",
|
||||
"unpipe": "~1.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/forwarded": {
|
||||
"version": "0.2.0",
|
||||
"resolved": "https://registry.npmmirror.com/forwarded/-/forwarded-0.2.0.tgz",
|
||||
"integrity": "sha512-buRG0fpBtRHSTCOASe6hD258tEubFoRLb4ZNA6NxMVHNw2gOcwHo9wyablzMzOA5z9xA9L1KNjk/Nt6MT9aYow==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/fresh": {
|
||||
"version": "0.5.2",
|
||||
"resolved": "https://registry.npmmirror.com/fresh/-/fresh-0.5.2.tgz",
|
||||
"integrity": "sha512-zJ2mQYM18rEFOudeV4GShTGIQ7RbzA7ozbU9I/XBpm7kqgMywgmylMwXHxZJmkVoYkna9d2pVXVXPdYTP9ej8Q==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/function-bind": {
|
||||
"version": "1.1.2",
|
||||
"resolved": "https://registry.npmmirror.com/function-bind/-/function-bind-1.1.2.tgz",
|
||||
"integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==",
|
||||
"license": "MIT",
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/get-intrinsic": {
|
||||
"version": "1.3.0",
|
||||
"resolved": "https://registry.npmmirror.com/get-intrinsic/-/get-intrinsic-1.3.0.tgz",
|
||||
"integrity": "sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"call-bind-apply-helpers": "^1.0.2",
|
||||
"es-define-property": "^1.0.1",
|
||||
"es-errors": "^1.3.0",
|
||||
"es-object-atoms": "^1.1.1",
|
||||
"function-bind": "^1.1.2",
|
||||
"get-proto": "^1.0.1",
|
||||
"gopd": "^1.2.0",
|
||||
"has-symbols": "^1.1.0",
|
||||
"hasown": "^2.0.2",
|
||||
"math-intrinsics": "^1.1.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/get-proto": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmmirror.com/get-proto/-/get-proto-1.0.1.tgz",
|
||||
"integrity": "sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"dunder-proto": "^1.0.1",
|
||||
"es-object-atoms": "^1.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/gopd": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmmirror.com/gopd/-/gopd-1.2.0.tgz",
|
||||
"integrity": "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/has-symbols": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmmirror.com/has-symbols/-/has-symbols-1.1.0.tgz",
|
||||
"integrity": "sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/hasown": {
|
||||
"version": "2.0.2",
|
||||
"resolved": "https://registry.npmmirror.com/hasown/-/hasown-2.0.2.tgz",
|
||||
"integrity": "sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"function-bind": "^1.1.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/http-errors": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmmirror.com/http-errors/-/http-errors-2.0.0.tgz",
|
||||
"integrity": "sha512-FtwrG/euBzaEjYeRqOgly7G0qviiXoJWnvEH2Z1plBdXgbyjv34pHTSb9zoeHMyDy33+DWy5Wt9Wo+TURtOYSQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"depd": "2.0.0",
|
||||
"inherits": "2.0.4",
|
||||
"setprototypeof": "1.2.0",
|
||||
"statuses": "2.0.1",
|
||||
"toidentifier": "1.0.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/iconv-lite": {
|
||||
"version": "0.4.24",
|
||||
"resolved": "https://registry.npmmirror.com/iconv-lite/-/iconv-lite-0.4.24.tgz",
|
||||
"integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"safer-buffer": ">= 2.1.2 < 3"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.10.0"
|
||||
}
|
||||
},
|
||||
"node_modules/inherits": {
|
||||
"version": "2.0.4",
|
||||
"resolved": "https://registry.npmmirror.com/inherits/-/inherits-2.0.4.tgz",
|
||||
"integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==",
|
||||
"license": "ISC"
|
||||
},
|
||||
"node_modules/ipaddr.js": {
|
||||
"version": "1.9.1",
|
||||
"resolved": "https://registry.npmmirror.com/ipaddr.js/-/ipaddr.js-1.9.1.tgz",
|
||||
"integrity": "sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.10"
|
||||
}
|
||||
},
|
||||
"node_modules/math-intrinsics": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmmirror.com/math-intrinsics/-/math-intrinsics-1.1.0.tgz",
|
||||
"integrity": "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/media-typer": {
|
||||
"version": "0.3.0",
|
||||
"resolved": "https://registry.npmmirror.com/media-typer/-/media-typer-0.3.0.tgz",
|
||||
"integrity": "sha512-dq+qelQ9akHpcOl/gUVRTxVIOkAJ1wR3QAvb4RsVjS8oVoFjDGTc679wJYmUmknUF5HwMLOgb5O+a3KxfWapPQ==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/merge-descriptors": {
|
||||
"version": "1.0.3",
|
||||
"resolved": "https://registry.npmmirror.com/merge-descriptors/-/merge-descriptors-1.0.3.tgz",
|
||||
"integrity": "sha512-gaNvAS7TZ897/rVaZ0nMtAyxNyi/pdbjbAwUpFQpN70GqnVfOiXpeUUMKRBmzXaSQ8DdTX4/0ms62r2K+hE6mQ==",
|
||||
"license": "MIT",
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/sindresorhus"
|
||||
}
|
||||
},
|
||||
"node_modules/methods": {
|
||||
"version": "1.1.2",
|
||||
"resolved": "https://registry.npmmirror.com/methods/-/methods-1.1.2.tgz",
|
||||
"integrity": "sha512-iclAHeNqNm68zFtnZ0e+1L2yUIdvzNoauKU4WBA3VvH/vPFieF7qfRlwUZU+DA9P9bPXIS90ulxoUoCH23sV2w==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/mime": {
|
||||
"version": "1.6.0",
|
||||
"resolved": "https://registry.npmmirror.com/mime/-/mime-1.6.0.tgz",
|
||||
"integrity": "sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg==",
|
||||
"license": "MIT",
|
||||
"bin": {
|
||||
"mime": "cli.js"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=4"
|
||||
}
|
||||
},
|
||||
"node_modules/mime-db": {
|
||||
"version": "1.52.0",
|
||||
"resolved": "https://registry.npmmirror.com/mime-db/-/mime-db-1.52.0.tgz",
|
||||
"integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/mime-types": {
|
||||
"version": "2.1.35",
|
||||
"resolved": "https://registry.npmmirror.com/mime-types/-/mime-types-2.1.35.tgz",
|
||||
"integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"mime-db": "1.52.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/ms": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmmirror.com/ms/-/ms-2.0.0.tgz",
|
||||
"integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/negotiator": {
|
||||
"version": "0.6.3",
|
||||
"resolved": "https://registry.npmmirror.com/negotiator/-/negotiator-0.6.3.tgz",
|
||||
"integrity": "sha512-+EUsqGPLsM+j/zdChZjsnX51g4XrHFOIXwfnCVPGlQk/k5giakcKsuxCObBRu6DSm9opw/O6slWbJdghQM4bBg==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/object-inspect": {
|
||||
"version": "1.13.4",
|
||||
"resolved": "https://registry.npmmirror.com/object-inspect/-/object-inspect-1.13.4.tgz",
|
||||
"integrity": "sha512-W67iLl4J2EXEGTbfeHCffrjDfitvLANg0UlX3wFUUSTx92KXRFegMHUVgSqE+wvhAbi4WqjGg9czysTV2Epbew==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/on-finished": {
|
||||
"version": "2.4.1",
|
||||
"resolved": "https://registry.npmmirror.com/on-finished/-/on-finished-2.4.1.tgz",
|
||||
"integrity": "sha512-oVlzkg3ENAhCk2zdv7IJwd/QUD4z2RxRwpkcGY8psCVcCYZNq4wYnVWALHM+brtuJjePWiYF/ClmuDr8Ch5+kg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"ee-first": "1.1.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/parseurl": {
|
||||
"version": "1.3.3",
|
||||
"resolved": "https://registry.npmmirror.com/parseurl/-/parseurl-1.3.3.tgz",
|
||||
"integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/path-to-regexp": {
|
||||
"version": "0.1.12",
|
||||
"resolved": "https://registry.npmmirror.com/path-to-regexp/-/path-to-regexp-0.1.12.tgz",
|
||||
"integrity": "sha512-RA1GjUVMnvYFxuqovrEqZoxxW5NUZqbwKtYz/Tt7nXerk0LbLblQmrsgdeOxV5SFHf0UDggjS/bSeOZwt1pmEQ==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/proxy-addr": {
|
||||
"version": "2.0.7",
|
||||
"resolved": "https://registry.npmmirror.com/proxy-addr/-/proxy-addr-2.0.7.tgz",
|
||||
"integrity": "sha512-llQsMLSUDUPT44jdrU/O37qlnifitDP+ZwrmmZcoSKyLKvtZxpyV0n2/bD/N4tBAAZ/gJEdZU7KMraoK1+XYAg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"forwarded": "0.2.0",
|
||||
"ipaddr.js": "1.9.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.10"
|
||||
}
|
||||
},
|
||||
"node_modules/qs": {
|
||||
"version": "6.13.0",
|
||||
"resolved": "https://registry.npmmirror.com/qs/-/qs-6.13.0.tgz",
|
||||
"integrity": "sha512-+38qI9SOr8tfZ4QmJNplMUxqjbe7LKvvZgWdExBOmd+egZTtjLB67Gu0HRX3u/XOq7UU2Nx6nsjvS16Z9uwfpg==",
|
||||
"license": "BSD-3-Clause",
|
||||
"dependencies": {
|
||||
"side-channel": "^1.0.6"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.6"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/range-parser": {
|
||||
"version": "1.2.1",
|
||||
"resolved": "https://registry.npmmirror.com/range-parser/-/range-parser-1.2.1.tgz",
|
||||
"integrity": "sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/raw-body": {
|
||||
"version": "2.5.2",
|
||||
"resolved": "https://registry.npmmirror.com/raw-body/-/raw-body-2.5.2.tgz",
|
||||
"integrity": "sha512-8zGqypfENjCIqGhgXToC8aB2r7YrBX+AQAfIPs/Mlk+BtPTztOvTS01NRW/3Eh60J+a48lt8qsCzirQ6loCVfA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"bytes": "3.1.2",
|
||||
"http-errors": "2.0.0",
|
||||
"iconv-lite": "0.4.24",
|
||||
"unpipe": "1.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/safe-buffer": {
|
||||
"version": "5.2.1",
|
||||
"resolved": "https://registry.npmmirror.com/safe-buffer/-/safe-buffer-5.2.1.tgz",
|
||||
"integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==",
|
||||
"funding": [
|
||||
{
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/feross"
|
||||
},
|
||||
{
|
||||
"type": "patreon",
|
||||
"url": "https://www.patreon.com/feross"
|
||||
},
|
||||
{
|
||||
"type": "consulting",
|
||||
"url": "https://feross.org/support"
|
||||
}
|
||||
],
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/safer-buffer": {
|
||||
"version": "2.1.2",
|
||||
"resolved": "https://registry.npmmirror.com/safer-buffer/-/safer-buffer-2.1.2.tgz",
|
||||
"integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/send": {
|
||||
"version": "0.19.0",
|
||||
"resolved": "https://registry.npmmirror.com/send/-/send-0.19.0.tgz",
|
||||
"integrity": "sha512-dW41u5VfLXu8SJh5bwRmyYUbAoSB3c9uQh6L8h/KtsFREPWpbX1lrljJo186Jc4nmci/sGUZ9a0a0J2zgfq2hw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"debug": "2.6.9",
|
||||
"depd": "2.0.0",
|
||||
"destroy": "1.2.0",
|
||||
"encodeurl": "~1.0.2",
|
||||
"escape-html": "~1.0.3",
|
||||
"etag": "~1.8.1",
|
||||
"fresh": "0.5.2",
|
||||
"http-errors": "2.0.0",
|
||||
"mime": "1.6.0",
|
||||
"ms": "2.1.3",
|
||||
"on-finished": "2.4.1",
|
||||
"range-parser": "~1.2.1",
|
||||
"statuses": "2.0.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.8.0"
|
||||
}
|
||||
},
|
||||
"node_modules/send/node_modules/encodeurl": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmmirror.com/encodeurl/-/encodeurl-1.0.2.tgz",
|
||||
"integrity": "sha512-TPJXq8JqFaVYm2CWmPvnP2Iyo4ZSM7/QKcSmuMLDObfpH5fi7RUGmd/rTDf+rut/saiDiQEeVTNgAmJEdAOx0w==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/send/node_modules/ms": {
|
||||
"version": "2.1.3",
|
||||
"resolved": "https://registry.npmmirror.com/ms/-/ms-2.1.3.tgz",
|
||||
"integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/serve-static": {
|
||||
"version": "1.16.2",
|
||||
"resolved": "https://registry.npmmirror.com/serve-static/-/serve-static-1.16.2.tgz",
|
||||
"integrity": "sha512-VqpjJZKadQB/PEbEwvFdO43Ax5dFBZ2UECszz8bQ7pi7wt//PWe1P6MN7eCnjsatYtBT6EuiClbjSWP2WrIoTw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"encodeurl": "~2.0.0",
|
||||
"escape-html": "~1.0.3",
|
||||
"parseurl": "~1.3.3",
|
||||
"send": "0.19.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.8.0"
|
||||
}
|
||||
},
|
||||
"node_modules/setprototypeof": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmmirror.com/setprototypeof/-/setprototypeof-1.2.0.tgz",
|
||||
"integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==",
|
||||
"license": "ISC"
|
||||
},
|
||||
"node_modules/side-channel": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmmirror.com/side-channel/-/side-channel-1.1.0.tgz",
|
||||
"integrity": "sha512-ZX99e6tRweoUXqR+VBrslhda51Nh5MTQwou5tnUDgbtyM0dBgmhEDtWGP/xbKn6hqfPRHujUNwz5fy/wbbhnpw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"es-errors": "^1.3.0",
|
||||
"object-inspect": "^1.13.3",
|
||||
"side-channel-list": "^1.0.0",
|
||||
"side-channel-map": "^1.0.1",
|
||||
"side-channel-weakmap": "^1.0.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/side-channel-list": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmmirror.com/side-channel-list/-/side-channel-list-1.0.0.tgz",
|
||||
"integrity": "sha512-FCLHtRD/gnpCiCHEiJLOwdmFP+wzCmDEkc9y7NsYxeF4u7Btsn1ZuwgwJGxImImHicJArLP4R0yX4c2KCrMrTA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"es-errors": "^1.3.0",
|
||||
"object-inspect": "^1.13.3"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/side-channel-map": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmmirror.com/side-channel-map/-/side-channel-map-1.0.1.tgz",
|
||||
"integrity": "sha512-VCjCNfgMsby3tTdo02nbjtM/ewra6jPHmpThenkTYh8pG9ucZ/1P8So4u4FGBek/BjpOVsDCMoLA/iuBKIFXRA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"call-bound": "^1.0.2",
|
||||
"es-errors": "^1.3.0",
|
||||
"get-intrinsic": "^1.2.5",
|
||||
"object-inspect": "^1.13.3"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/side-channel-weakmap": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmmirror.com/side-channel-weakmap/-/side-channel-weakmap-1.0.2.tgz",
|
||||
"integrity": "sha512-WPS/HvHQTYnHisLo9McqBHOJk2FkHO/tlpvldyrnem4aeQp4hai3gythswg6p01oSoTl58rcpiFAjF2br2Ak2A==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"call-bound": "^1.0.2",
|
||||
"es-errors": "^1.3.0",
|
||||
"get-intrinsic": "^1.2.5",
|
||||
"object-inspect": "^1.13.3",
|
||||
"side-channel-map": "^1.0.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/statuses": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmmirror.com/statuses/-/statuses-2.0.1.tgz",
|
||||
"integrity": "sha512-RwNA9Z/7PrK06rYLIzFMlaF+l73iwpzsqRIFgbMLbTcLD6cOao82TaWefPXQvB2fOC4AjuYSEndS7N/mTCbkdQ==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/toidentifier": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmmirror.com/toidentifier/-/toidentifier-1.0.1.tgz",
|
||||
"integrity": "sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/type-is": {
|
||||
"version": "1.6.18",
|
||||
"resolved": "https://registry.npmmirror.com/type-is/-/type-is-1.6.18.tgz",
|
||||
"integrity": "sha512-TkRKr9sUTxEH8MdfuCSP7VizJyzRNMjj2J2do2Jr3Kym598JVdEksuzPQCnlFPW4ky9Q+iA+ma9BGm06XQBy8g==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"media-typer": "0.3.0",
|
||||
"mime-types": "~2.1.24"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/unpipe": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmmirror.com/unpipe/-/unpipe-1.0.0.tgz",
|
||||
"integrity": "sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/utils-merge": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmmirror.com/utils-merge/-/utils-merge-1.0.1.tgz",
|
||||
"integrity": "sha512-pMZTvIkT1d+TFGvDOqodOclx0QWkkgi6Tdoa8gC8ffGAAqz9pzPTZWAybbsHHoED/ztMtkv/VoYTYyShUn81hA==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.4.0"
|
||||
}
|
||||
},
|
||||
"node_modules/vary": {
|
||||
"version": "1.1.2",
|
||||
"resolved": "https://registry.npmmirror.com/vary/-/vary-1.1.2.tgz",
|
||||
"integrity": "sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/ws": {
|
||||
"version": "8.18.1",
|
||||
"resolved": "https://registry.npmmirror.com/ws/-/ws-8.18.1.tgz",
|
||||
"integrity": "sha512-RKW2aJZMXeMxVpnZ6bck+RswznaxmzdULiBr6KY7XkTnW8uvt0iT9H5DkHUChXrc+uurzwa0rVI16n/Xzjdz1w==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=10.0.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"bufferutil": "^4.0.1",
|
||||
"utf-8-validate": ">=5.0.2"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"bufferutil": {
|
||||
"optional": true
|
||||
},
|
||||
"utf-8-validate": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
10
asr-server/package.json
Normal file
10
asr-server/package.json
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"name": "cherry-asr-server",
|
||||
"version": "1.0.0",
|
||||
"description": "Cherry Studio ASR Server",
|
||||
"main": "server.js",
|
||||
"dependencies": {
|
||||
"express": "^4.18.2",
|
||||
"ws": "^8.13.0"
|
||||
}
|
||||
}
|
||||
269
asr-server/server.js
Normal file
269
asr-server/server.js
Normal file
@ -0,0 +1,269 @@
|
||||
// 检查依赖项
|
||||
try {
|
||||
console.log('ASR Server starting...')
|
||||
console.log('Node.js version:', process.version)
|
||||
console.log('Current directory:', __dirname)
|
||||
console.log('Current working directory:', process.cwd())
|
||||
console.log('Command line arguments:', process.argv)
|
||||
|
||||
// 检查必要的依赖项
|
||||
const checkDependency = (name) => {
|
||||
try {
|
||||
require(name) // Removed unused variable 'module'
|
||||
console.log(`Successfully loaded dependency: ${name}`)
|
||||
return true
|
||||
} catch (error) {
|
||||
console.error(`Failed to load dependency: ${name}`, error.message)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// 检查所有必要的依赖项
|
||||
const dependencies = ['http', 'ws', 'express', 'path', 'fs']
|
||||
const missingDeps = dependencies.filter((dep) => !checkDependency(dep))
|
||||
|
||||
if (missingDeps.length > 0) {
|
||||
console.error(`Missing dependencies: ${missingDeps.join(', ')}. Server cannot start.`)
|
||||
process.exit(1)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error during dependency check:', error)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
// 加载依赖项
|
||||
const http = require('http')
|
||||
const WebSocket = require('ws')
|
||||
const express = require('express')
|
||||
const path = require('path') // Need path module
|
||||
// const fs = require('fs') // Commented out unused import 'fs'
|
||||
|
||||
const app = express()
|
||||
const port = 34515 // Define the port
|
||||
|
||||
// 获取index.html文件的路径
|
||||
function getIndexHtmlPath() {
|
||||
const fs = require('fs')
|
||||
console.log('Current directory:', __dirname)
|
||||
console.log('Current working directory:', process.cwd())
|
||||
|
||||
// 尝试多个可能的路径
|
||||
const possiblePaths = [
|
||||
// 开发环境路径
|
||||
path.join(__dirname, 'index.html'),
|
||||
// 当前目录
|
||||
path.join(process.cwd(), 'index.html'),
|
||||
// 相对于可执行文件的路径
|
||||
path.join(path.dirname(process.execPath), 'index.html'),
|
||||
// 相对于可执行文件的上级目录的路径
|
||||
path.join(path.dirname(path.dirname(process.execPath)), 'index.html'),
|
||||
// 相对于可执行文件的resources目录的路径
|
||||
path.join(path.dirname(process.execPath), 'resources', 'index.html'),
|
||||
// 相对于可执行文件的resources/asr-server目录的路径
|
||||
path.join(path.dirname(process.execPath), 'resources', 'asr-server', 'index.html'),
|
||||
// 相对于可执行文件的asr-server目录的路径
|
||||
path.join(path.dirname(process.execPath), 'asr-server', 'index.html'),
|
||||
// 如果是pkg打包环境
|
||||
process.pkg ? path.join(path.dirname(process.execPath), 'index.html') : null
|
||||
].filter(Boolean) // 过滤掉null值
|
||||
|
||||
console.log('Possible index.html paths:', possiblePaths)
|
||||
|
||||
// 检查每个路径,返回第一个存在的文件
|
||||
for (const p of possiblePaths) {
|
||||
try {
|
||||
if (fs.existsSync(p)) {
|
||||
console.log(`Found index.html at: ${p}`)
|
||||
return p
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(`Error checking existence of ${p}:`, e)
|
||||
}
|
||||
}
|
||||
|
||||
// 如果没有找到文件,返回默认路径并记录错误
|
||||
console.error('Could not find index.html in any of the expected locations')
|
||||
return path.join(__dirname, 'index.html') // 返回默认路径,即使它可能不存在
|
||||
}
|
||||
|
||||
// 提供网页给浏览器
|
||||
app.get('/', (req, res) => {
|
||||
try {
|
||||
const indexPath = getIndexHtmlPath()
|
||||
console.log(`Serving index.html from: ${indexPath}`)
|
||||
|
||||
// 检查文件是否存在
|
||||
const fs = require('fs')
|
||||
if (!fs.existsSync(indexPath)) {
|
||||
console.error(`Error: index.html not found at ${indexPath}`)
|
||||
return res.status(404).send(`Error: index.html not found at ${indexPath}. <br>Please check the server logs.`)
|
||||
}
|
||||
|
||||
res.sendFile(indexPath, (err) => {
|
||||
if (err) {
|
||||
console.error('Error sending index.html:', err)
|
||||
res.status(500).send(`Error serving index.html: ${err.message}`)
|
||||
}
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('Error in route handler:', error)
|
||||
res.status(500).send(`Server error: ${error.message}`)
|
||||
}
|
||||
})
|
||||
|
||||
const server = http.createServer(app)
|
||||
const wss = new WebSocket.Server({ server })
|
||||
|
||||
let browserConnection = null
|
||||
let electronConnection = null
|
||||
|
||||
wss.on('connection', (ws) => {
|
||||
console.log('[Server] WebSocket client connected') // Add log
|
||||
|
||||
ws.on('message', (message) => {
|
||||
let data
|
||||
try {
|
||||
// Ensure message is treated as string before parsing
|
||||
data = JSON.parse(message.toString())
|
||||
console.log('[Server] Received message:', data) // Log parsed data
|
||||
} catch (e) {
|
||||
console.error('[Server] Failed to parse message or message is not JSON:', message.toString(), e)
|
||||
return // Ignore non-JSON messages
|
||||
}
|
||||
|
||||
// 识别客户端类型
|
||||
if (data.type === 'identify') {
|
||||
if (data.role === 'browser') {
|
||||
browserConnection = ws
|
||||
console.log('[Server] Browser identified and connected')
|
||||
// Notify Electron that the browser is ready
|
||||
if (electronConnection && electronConnection.readyState === WebSocket.OPEN) {
|
||||
electronConnection.send(JSON.stringify({ type: 'status', message: 'browser_ready' }))
|
||||
console.log('[Server] Sent browser_ready status to Electron')
|
||||
}
|
||||
// Notify Electron if it's already connected
|
||||
if (electronConnection) {
|
||||
electronConnection.send(JSON.stringify({ type: 'status', message: 'Browser connected' }))
|
||||
}
|
||||
ws.on('close', () => {
|
||||
console.log('[Server] Browser disconnected')
|
||||
browserConnection = null
|
||||
// Notify Electron
|
||||
if (electronConnection) {
|
||||
electronConnection.send(JSON.stringify({ type: 'status', message: 'Browser disconnected' }))
|
||||
}
|
||||
})
|
||||
ws.on('error', (error) => {
|
||||
console.error('[Server] Browser WebSocket error:', error)
|
||||
browserConnection = null // Assume disconnected on error
|
||||
if (electronConnection) {
|
||||
electronConnection.send(JSON.stringify({ type: 'status', message: 'Browser connection error' }))
|
||||
}
|
||||
})
|
||||
} else if (data.role === 'electron') {
|
||||
electronConnection = ws
|
||||
console.log('[Server] Electron identified and connected')
|
||||
// If browser is already connected when Electron connects, notify Electron immediately
|
||||
if (browserConnection && browserConnection.readyState === WebSocket.OPEN) {
|
||||
electronConnection.send(JSON.stringify({ type: 'status', message: 'browser_ready' }))
|
||||
console.log('[Server] Sent initial browser_ready status to Electron')
|
||||
}
|
||||
ws.on('close', () => {
|
||||
console.log('[Server] Electron disconnected')
|
||||
electronConnection = null
|
||||
// Maybe send stop to browser if electron disconnects?
|
||||
// if (browserConnection) browserConnection.send(JSON.stringify({ type: 'stop' }));
|
||||
})
|
||||
ws.on('error', (error) => {
|
||||
console.error('[Server] Electron WebSocket error:', error)
|
||||
electronConnection = null // Assume disconnected on error
|
||||
})
|
||||
}
|
||||
}
|
||||
// Electron 控制开始/停止
|
||||
else if (data.type === 'start' && ws === electronConnection) {
|
||||
if (browserConnection && browserConnection.readyState === WebSocket.OPEN) {
|
||||
console.log('[Server] Relaying START command to browser')
|
||||
browserConnection.send(JSON.stringify({ type: 'start' }))
|
||||
} else {
|
||||
console.log('[Server] Cannot relay START: Browser not connected')
|
||||
// Optionally notify Electron back
|
||||
electronConnection.send(JSON.stringify({ type: 'error', message: 'Browser not connected for ASR' }))
|
||||
}
|
||||
} else if (data.type === 'stop' && ws === electronConnection) {
|
||||
if (browserConnection && browserConnection.readyState === WebSocket.OPEN) {
|
||||
console.log('[Server] Relaying STOP command to browser')
|
||||
browserConnection.send(JSON.stringify({ type: 'stop' }))
|
||||
} else {
|
||||
console.log('[Server] Cannot relay STOP: Browser not connected')
|
||||
}
|
||||
} else if (data.type === 'reset' && ws === electronConnection) {
|
||||
if (browserConnection && browserConnection.readyState === WebSocket.OPEN) {
|
||||
console.log('[Server] Relaying RESET command to browser')
|
||||
browserConnection.send(JSON.stringify({ type: 'reset' }))
|
||||
} else {
|
||||
console.log('[Server] Cannot relay RESET: Browser not connected')
|
||||
}
|
||||
}
|
||||
// 浏览器发送识别结果
|
||||
else if (data.type === 'result' && ws === browserConnection) {
|
||||
if (electronConnection && electronConnection.readyState === WebSocket.OPEN) {
|
||||
// console.log('[Server] Relaying RESULT to Electron:', data.data); // Log less frequently if needed
|
||||
electronConnection.send(JSON.stringify({ type: 'result', data: data.data }))
|
||||
} else {
|
||||
// console.log('[Server] Cannot relay RESULT: Electron not connected');
|
||||
}
|
||||
}
|
||||
// 浏览器发送状态更新 (例如 'stopped')
|
||||
else if (data.type === 'status' && ws === browserConnection) {
|
||||
if (electronConnection && electronConnection.readyState === WebSocket.OPEN) {
|
||||
console.log('[Server] Relaying STATUS to Electron:', data.message) // Log status being relayed
|
||||
electronConnection.send(JSON.stringify({ type: 'status', message: data.message }))
|
||||
} else {
|
||||
console.log('[Server] Cannot relay STATUS: Electron not connected')
|
||||
}
|
||||
} else {
|
||||
console.log('[Server] Received unknown message type or from unknown source:', data)
|
||||
}
|
||||
})
|
||||
|
||||
ws.on('error', (error) => {
|
||||
// Generic error handling for connection before identification
|
||||
console.error('[Server] Initial WebSocket connection error:', error)
|
||||
// Attempt to clean up based on which connection it might be (if identified)
|
||||
if (ws === browserConnection) {
|
||||
browserConnection = null
|
||||
if (electronConnection)
|
||||
electronConnection.send(JSON.stringify({ type: 'status', message: 'Browser connection error' }))
|
||||
} else if (ws === electronConnection) {
|
||||
electronConnection = null
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
// 添加进程错误处理
|
||||
process.on('uncaughtException', (error) => {
|
||||
console.error('[Server] Uncaught exception:', error)
|
||||
// 不立即退出,给日志输出的时间
|
||||
setTimeout(() => process.exit(1), 1000)
|
||||
})
|
||||
|
||||
process.on('unhandledRejection', (reason, promise) => {
|
||||
console.error('[Server] Unhandled rejection at:', promise, 'reason:', reason)
|
||||
})
|
||||
|
||||
// 尝试启动服务器
|
||||
try {
|
||||
server.listen(port, () => {
|
||||
console.log(`[Server] Server running at http://localhost:${port}`)
|
||||
})
|
||||
|
||||
// Handle server errors
|
||||
server.on('error', (error) => {
|
||||
console.error(`[Server] Failed to start server:`, error)
|
||||
process.exit(1) // Exit if server fails to start
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('[Server] Critical error starting server:', error)
|
||||
process.exit(1)
|
||||
}
|
||||
114
asr-server/standalone.js
Normal file
114
asr-server/standalone.js
Normal file
@ -0,0 +1,114 @@
|
||||
/**
|
||||
* 独立的ASR服务器
|
||||
* 这个文件是一个简化版的server.js,用于在打包后的应用中运行
|
||||
*/
|
||||
|
||||
// 基本依赖
|
||||
const http = require('http')
|
||||
const express = require('express')
|
||||
const path = require('path')
|
||||
const fs = require('fs')
|
||||
|
||||
// 输出环境信息
|
||||
console.log('ASR Server starting...')
|
||||
console.log('Node.js version:', process.version)
|
||||
console.log('Current directory:', __dirname)
|
||||
console.log('Current working directory:', process.cwd())
|
||||
console.log('Command line arguments:', process.argv)
|
||||
|
||||
// 创建Express应用
|
||||
const app = express()
|
||||
const port = 34515
|
||||
|
||||
// 提供静态文件
|
||||
app.use(express.static(__dirname))
|
||||
|
||||
// 提供网页给浏览器
|
||||
app.get('/', (req, res) => {
|
||||
try {
|
||||
// 尝试多个可能的路径
|
||||
const possiblePaths = [
|
||||
// 当前目录
|
||||
path.join(__dirname, 'index.html'),
|
||||
// 上级目录
|
||||
path.join(__dirname, '..', 'index.html'),
|
||||
// 应用根目录
|
||||
path.join(process.cwd(), 'index.html')
|
||||
]
|
||||
|
||||
console.log('Possible index.html paths:', possiblePaths)
|
||||
|
||||
// 查找第一个存在的文件
|
||||
let indexPath = null
|
||||
for (const p of possiblePaths) {
|
||||
try {
|
||||
if (fs.existsSync(p)) {
|
||||
indexPath = p
|
||||
console.log(`Found index.html at: ${p}`)
|
||||
break
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(`Error checking existence of ${p}:`, e)
|
||||
}
|
||||
}
|
||||
|
||||
if (indexPath) {
|
||||
res.sendFile(indexPath)
|
||||
} else {
|
||||
// 如果找不到文件,返回一个简单的HTML页面
|
||||
console.error('Could not find index.html, serving fallback page')
|
||||
res.send(`
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>ASR Server</title>
|
||||
<style>
|
||||
body { font-family: sans-serif; padding: 2em; }
|
||||
h1 { color: #333; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>ASR Server is running</h1>
|
||||
<p>This is a fallback page because the index.html file could not be found.</p>
|
||||
<p>Server is running at: http://localhost:${port}</p>
|
||||
<p>Current directory: ${__dirname}</p>
|
||||
<p>Working directory: ${process.cwd()}</p>
|
||||
</body>
|
||||
</html>
|
||||
`)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error serving index.html:', error)
|
||||
res.status(500).send(`Server error: ${error.message}`)
|
||||
}
|
||||
})
|
||||
|
||||
// 创建HTTP服务器
|
||||
const server = http.createServer(app)
|
||||
|
||||
// 添加进程错误处理
|
||||
process.on('uncaughtException', (error) => {
|
||||
console.error('[Server] Uncaught exception:', error)
|
||||
// 不立即退出,给日志输出的时间
|
||||
setTimeout(() => process.exit(1), 1000)
|
||||
})
|
||||
|
||||
process.on('unhandledRejection', (reason, promise) => {
|
||||
console.error('[Server] Unhandled rejection at:', promise, 'reason:', reason)
|
||||
})
|
||||
|
||||
// 尝试启动服务器
|
||||
try {
|
||||
server.listen(port, () => {
|
||||
console.log(`[Server] Server running at http://localhost:${port}`)
|
||||
})
|
||||
|
||||
// 处理服务器错误
|
||||
server.on('error', (error) => {
|
||||
console.error(`[Server] Failed to start server:`, error)
|
||||
process.exit(1) // Exit if server fails to start
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('[Server] Critical error starting server:', error)
|
||||
process.exit(1)
|
||||
}
|
||||
5
asr-server/start-server.bat
Normal file
5
asr-server/start-server.bat
Normal file
@ -0,0 +1,5 @@
|
||||
@echo off
|
||||
echo Starting ASR Server...
|
||||
cd /d %~dp0
|
||||
node standalone.js
|
||||
pause
|
||||
@ -29,14 +29,18 @@ files:
|
||||
- '!node_modules/@tavily/core/node_modules/js-tiktoken'
|
||||
- '!node_modules/pdf-parse/lib/pdf.js/{v1.9.426,v1.10.88,v2.0.550}'
|
||||
- '!node_modules/mammoth/{mammoth.browser.js,mammoth.browser.min.js}'
|
||||
# 包含 ASR 服务器文件
|
||||
- src/renderer/src/assets/asr-server/**/*
|
||||
# 包含打包后的ASR服务器可执行文件
|
||||
- cherry-asr-server.exe
|
||||
- index.html
|
||||
asarUnpack:
|
||||
asarUnpack: # Removed ASR server rules from 'files' section
|
||||
- resources/**
|
||||
- '**/*.{node,dll,metal,exp,lib}'
|
||||
extraResources: # Add extraResources to copy the prepared asr-server directory
|
||||
- from: asr-server # Copy the folder from project root
|
||||
to: app/asr-server # Copy TO the 'app' subfolder within resources
|
||||
filter:
|
||||
- "**/*" # Include everything inside
|
||||
- from: resources/data # Copy the data folder with agents.json
|
||||
to: data # Copy TO the 'data' subfolder within resources
|
||||
filter:
|
||||
- "**/*" # Include everything inside
|
||||
win:
|
||||
executableName: Cherry Studio
|
||||
artifactName: ${productName}-${version}-${arch}-setup.${ext}
|
||||
|
||||
425
index.html
Normal file
425
index.html
Normal file
@ -0,0 +1,425 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Cherry Studio ASR</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: sans-serif;
|
||||
padding: 1em;
|
||||
}
|
||||
|
||||
#status {
|
||||
margin-top: 1em;
|
||||
font-style: italic;
|
||||
color: #555;
|
||||
}
|
||||
|
||||
#result {
|
||||
margin-top: 0.5em;
|
||||
border: 1px solid #ccc;
|
||||
padding: 0.5em;
|
||||
min-height: 50px;
|
||||
background: #f9f9f9;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>浏览器语音识别中继页面</h1>
|
||||
<p>这个页面需要在浏览器中保持打开,以便应用使用其语音识别功能。</p>
|
||||
<div id="status">正在连接到服务器...</div>
|
||||
<div id="result"></div>
|
||||
|
||||
<script>
|
||||
const statusDiv = document.getElementById('status');
|
||||
const resultDiv = document.getElementById('result');
|
||||
// 尝试连接到WebSocket服务器
|
||||
let ws;
|
||||
let reconnectAttempts = 0;
|
||||
const maxReconnectAttempts = 5;
|
||||
const reconnectInterval = 2000; // 2秒
|
||||
|
||||
function connectWebSocket() {
|
||||
try {
|
||||
ws = new WebSocket('ws://localhost:34515');
|
||||
|
||||
ws.onopen = () => {
|
||||
reconnectAttempts = 0;
|
||||
updateStatus('已连接到服务器,等待指令...');
|
||||
ws.send(JSON.stringify({ type: 'identify', role: 'browser' }));
|
||||
};
|
||||
|
||||
ws.onmessage = handleMessage;
|
||||
|
||||
ws.onerror = (error) => {
|
||||
console.error('[Browser Page] WebSocket Error:', error);
|
||||
updateStatus('WebSocket 连接错误!请检查服务器是否运行。');
|
||||
};
|
||||
|
||||
ws.onclose = () => {
|
||||
console.log('[Browser Page] WebSocket Connection Closed');
|
||||
updateStatus('与服务器断开连接。尝试重新连接...');
|
||||
stopRecognition();
|
||||
|
||||
// 尝试重新连接
|
||||
if (reconnectAttempts < maxReconnectAttempts) {
|
||||
reconnectAttempts++;
|
||||
updateStatus(`与服务器断开连接。尝试重新连接 (${reconnectAttempts}/${maxReconnectAttempts})...`);
|
||||
setTimeout(connectWebSocket, reconnectInterval);
|
||||
} else {
|
||||
updateStatus('无法连接到服务器。请刷新页面或重启应用。');
|
||||
}
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('[Browser Page] Error creating WebSocket:', error);
|
||||
updateStatus('创建WebSocket连接时出错。请刷新页面或重启应用。');
|
||||
}
|
||||
}
|
||||
|
||||
// 初始连接
|
||||
connectWebSocket();
|
||||
let recognition = null;
|
||||
const SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
|
||||
|
||||
function updateStatus(message) {
|
||||
console.log(`[Browser Page Status] ${message}`);
|
||||
statusDiv.textContent = message;
|
||||
}
|
||||
|
||||
function handleMessage(event) {
|
||||
let data;
|
||||
try {
|
||||
data = JSON.parse(event.data);
|
||||
console.log('[Browser Page] Received command:', data);
|
||||
} catch (e) {
|
||||
console.error('[Browser Page] Received non-JSON message:', event.data);
|
||||
return;
|
||||
}
|
||||
|
||||
if (data.type === 'start') {
|
||||
startRecognition();
|
||||
} else if (data.type === 'stop') {
|
||||
stopRecognition();
|
||||
} else if (data.type === 'reset') {
|
||||
// 强制重置语音识别
|
||||
forceResetRecognition();
|
||||
} else {
|
||||
console.warn('[Browser Page] Received unknown command type:', data.type);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
function setupRecognition() {
|
||||
if (!SpeechRecognition) {
|
||||
updateStatus('错误:此浏览器不支持 Web Speech API。');
|
||||
return false;
|
||||
}
|
||||
if (recognition && recognition.recognizing) {
|
||||
console.log('[Browser Page] Recognition already active.');
|
||||
return true;
|
||||
}
|
||||
|
||||
recognition = new SpeechRecognition();
|
||||
recognition.lang = 'zh-CN';
|
||||
recognition.continuous = true;
|
||||
recognition.interimResults = true;
|
||||
// 增加以下设置提高语音识别的可靠性
|
||||
recognition.maxAlternatives = 3; // 返回多个可能的识别结果
|
||||
// 设置较短的语音识别时间,使用户能更快地看到结果
|
||||
// 注意:这个属性不是标准的,可能不是所有浏览器都支持
|
||||
try {
|
||||
// @ts-ignore
|
||||
recognition.audioStart = 0.1; // 尝试设置较低的起始音量阈值
|
||||
} catch (e) {
|
||||
console.log('[Browser Page] audioStart property not supported');
|
||||
}
|
||||
|
||||
recognition.onstart = () => {
|
||||
updateStatus("🎤 正在识别...");
|
||||
console.log('[Browser Page] SpeechRecognition started.');
|
||||
};
|
||||
|
||||
recognition.onresult = (event) => {
|
||||
console.log('[Browser Page] Recognition result event:', event);
|
||||
|
||||
let interim_transcript = '';
|
||||
let final_transcript = '';
|
||||
|
||||
// 输出识别结果的详细信息便于调试
|
||||
for (let i = event.resultIndex; i < event.results.length; ++i) {
|
||||
const confidence = event.results[i][0].confidence;
|
||||
console.log(`[Browser Page] Result ${i}: ${event.results[i][0].transcript} (Confidence: ${confidence.toFixed(2)})`);
|
||||
|
||||
if (event.results[i].isFinal) {
|
||||
final_transcript += event.results[i][0].transcript;
|
||||
} else {
|
||||
interim_transcript += event.results[i][0].transcript;
|
||||
}
|
||||
}
|
||||
|
||||
const resultText = final_transcript || interim_transcript;
|
||||
resultDiv.textContent = resultText;
|
||||
|
||||
// 更新状态显示
|
||||
if (resultText) {
|
||||
updateStatus(`🎤 正在识别... (已捕捉到语音)`);
|
||||
}
|
||||
|
||||
if (ws.readyState === WebSocket.OPEN) {
|
||||
console.log(`[Browser Page] Sending ${final_transcript ? 'final' : 'interim'} result to server:`, resultText);
|
||||
ws.send(JSON.stringify({ type: 'result', data: { text: resultText, isFinal: !!final_transcript } }));
|
||||
}
|
||||
};
|
||||
|
||||
recognition.onerror = (event) => {
|
||||
console.error(`[Browser Page] SpeechRecognition Error - Type: ${event.error}, Message: ${event.message}`);
|
||||
|
||||
// 根据错误类型提供更友好的错误提示
|
||||
let errorMessage = '';
|
||||
switch (event.error) {
|
||||
case 'no-speech':
|
||||
errorMessage = '未检测到语音,请确保麦克风工作正常并尝试说话。';
|
||||
// 尝试重新启动语音识别
|
||||
setTimeout(() => {
|
||||
if (recognition) {
|
||||
try {
|
||||
recognition.start();
|
||||
console.log('[Browser Page] Restarting recognition after no-speech error');
|
||||
} catch (e) {
|
||||
console.error('[Browser Page] Failed to restart recognition:', e);
|
||||
}
|
||||
}
|
||||
}, 1000);
|
||||
break;
|
||||
case 'audio-capture':
|
||||
errorMessage = '无法捕获音频,请确保麦克风已连接并已授权。';
|
||||
break;
|
||||
case 'not-allowed':
|
||||
errorMessage = '浏览器不允许使用麦克风,请检查权限设置。';
|
||||
break;
|
||||
case 'network':
|
||||
errorMessage = '网络错误导致语音识别失败。';
|
||||
break;
|
||||
case 'aborted':
|
||||
errorMessage = '语音识别被用户或系统中止。';
|
||||
break;
|
||||
default:
|
||||
errorMessage = `识别错误: ${event.error}`;
|
||||
}
|
||||
|
||||
updateStatus(`错误: ${errorMessage}`);
|
||||
|
||||
if (ws.readyState === WebSocket.OPEN) {
|
||||
ws.send(JSON.stringify({
|
||||
type: 'error',
|
||||
data: {
|
||||
error: event.error,
|
||||
message: errorMessage || event.message || `Recognition error: ${event.error}`
|
||||
}
|
||||
}));
|
||||
}
|
||||
};
|
||||
|
||||
recognition.onend = () => {
|
||||
console.log('[Browser Page] SpeechRecognition ended.');
|
||||
|
||||
// 检查是否是由于错误或用户手动停止导致的结束
|
||||
const isErrorOrStopped = statusDiv.textContent.includes('错误') || statusDiv.textContent.includes('停止');
|
||||
|
||||
if (!isErrorOrStopped) {
|
||||
// 如果不是由于错误或手动停止,则自动重新启动语音识别
|
||||
updateStatus("识别暂停,正在重新启动...");
|
||||
|
||||
// 保存当前的recognition对象
|
||||
const currentRecognition = recognition;
|
||||
|
||||
// 尝试重新启动语音识别
|
||||
setTimeout(() => {
|
||||
try {
|
||||
if (currentRecognition && currentRecognition === recognition) {
|
||||
currentRecognition.start();
|
||||
console.log('[Browser Page] Automatically restarting recognition');
|
||||
} else {
|
||||
// 如果recognition对象已经变化,重新创建一个
|
||||
setupRecognition();
|
||||
if (recognition) {
|
||||
recognition.start();
|
||||
console.log('[Browser Page] Created new recognition instance and started');
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('[Browser Page] Failed to restart recognition:', e);
|
||||
updateStatus("识别已停止。等待指令...");
|
||||
}
|
||||
}, 300);
|
||||
} else {
|
||||
updateStatus("识别已停止。等待指令...");
|
||||
|
||||
if (ws.readyState === WebSocket.OPEN) {
|
||||
ws.send(JSON.stringify({ type: 'status', message: 'stopped' }));
|
||||
}
|
||||
|
||||
// 只有在手动停止或错误时才重置recognition对象
|
||||
recognition = null;
|
||||
}
|
||||
};
|
||||
return true;
|
||||
}
|
||||
|
||||
function startRecognition() {
|
||||
if (!SpeechRecognition) {
|
||||
updateStatus('错误:浏览器不支持 Web Speech API。');
|
||||
return;
|
||||
}
|
||||
|
||||
// 显示正在准备的状态
|
||||
updateStatus('正在准备麦克风...');
|
||||
|
||||
if (recognition) {
|
||||
console.log('[Browser Page] Recognition already exists, stopping first.');
|
||||
stopRecognition();
|
||||
}
|
||||
|
||||
if (!setupRecognition()) return;
|
||||
|
||||
console.log('[Browser Page] Attempting to start recognition...');
|
||||
try {
|
||||
// 设置更长的超时时间,确保有足够的时间获取麦克风权限
|
||||
const micPermissionTimeout = setTimeout(() => {
|
||||
updateStatus('获取麦克风权限超时,请刷新页面重试。');
|
||||
}, 10000); // 10秒超时
|
||||
|
||||
navigator.mediaDevices.getUserMedia({
|
||||
audio: {
|
||||
echoCancellation: true,
|
||||
noiseSuppression: true,
|
||||
autoGainControl: true
|
||||
}
|
||||
})
|
||||
.then(stream => {
|
||||
clearTimeout(micPermissionTimeout);
|
||||
console.log('[Browser Page] Microphone access granted.');
|
||||
|
||||
// 检查麦克风音量级别
|
||||
const audioContext = new AudioContext();
|
||||
const analyser = audioContext.createAnalyser();
|
||||
const microphone = audioContext.createMediaStreamSource(stream);
|
||||
const javascriptNode = audioContext.createScriptProcessor(2048, 1, 1);
|
||||
|
||||
analyser.smoothingTimeConstant = 0.8;
|
||||
analyser.fftSize = 1024;
|
||||
|
||||
microphone.connect(analyser);
|
||||
analyser.connect(javascriptNode);
|
||||
javascriptNode.connect(audioContext.destination);
|
||||
|
||||
javascriptNode.onaudioprocess = function () {
|
||||
const array = new Uint8Array(analyser.frequencyBinCount);
|
||||
analyser.getByteFrequencyData(array);
|
||||
let values = 0;
|
||||
|
||||
const length = array.length;
|
||||
for (let i = 0; i < length; i++) {
|
||||
values += (array[i]);
|
||||
}
|
||||
|
||||
const average = values / length;
|
||||
console.log('[Browser Page] Microphone volume level:', average);
|
||||
|
||||
// 如果音量太低,显示提示
|
||||
if (average < 5) {
|
||||
updateStatus('麦克风音量很低,请说话或检查麦克风设置。');
|
||||
} else {
|
||||
updateStatus('🎤 正在识别...');
|
||||
}
|
||||
|
||||
// 只检查一次就断开连接
|
||||
microphone.disconnect();
|
||||
analyser.disconnect();
|
||||
javascriptNode.disconnect();
|
||||
};
|
||||
|
||||
// 释放测试用的音频流
|
||||
setTimeout(() => {
|
||||
stream.getTracks().forEach(track => track.stop());
|
||||
audioContext.close();
|
||||
}, 1000);
|
||||
|
||||
// 启动语音识别
|
||||
if (recognition) {
|
||||
recognition.start();
|
||||
updateStatus('🎤 正在识别...');
|
||||
} else {
|
||||
updateStatus('错误:Recognition 实例丢失。');
|
||||
console.error('[Browser Page] Recognition instance lost before start.');
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
clearTimeout(micPermissionTimeout);
|
||||
console.error('[Browser Page] Microphone access error:', err);
|
||||
|
||||
let errorMsg = `无法访问麦克风 (${err.name})`;
|
||||
if (err.name === 'NotAllowedError') {
|
||||
errorMsg = '麦克风访问被拒绝。请在浏览器设置中允许麦克风访问权限。';
|
||||
} else if (err.name === 'NotFoundError') {
|
||||
errorMsg = '未找到麦克风设备。请确保麦克风已连接。';
|
||||
}
|
||||
|
||||
updateStatus(`错误: ${errorMsg}`);
|
||||
recognition = null;
|
||||
});
|
||||
} catch (e) {
|
||||
console.error('[Browser Page] Error calling recognition.start():', e);
|
||||
updateStatus(`启动识别时出错: ${e.message}`);
|
||||
recognition = null;
|
||||
}
|
||||
}
|
||||
|
||||
function stopRecognition() {
|
||||
if (recognition) {
|
||||
console.log('[Browser Page] Stopping recognition...');
|
||||
updateStatus("正在停止识别...");
|
||||
try {
|
||||
recognition.stop();
|
||||
} catch (e) {
|
||||
console.error('[Browser Page] Error calling recognition.stop():', e);
|
||||
recognition = null;
|
||||
updateStatus("停止时出错,已强制重置。");
|
||||
}
|
||||
} else {
|
||||
console.log('[Browser Page] Recognition not active, nothing to stop.');
|
||||
updateStatus("识别未运行。");
|
||||
}
|
||||
}
|
||||
|
||||
function forceResetRecognition() {
|
||||
console.log('[Browser Page] Force resetting recognition...');
|
||||
updateStatus("强制重置语音识别...");
|
||||
|
||||
// 先尝试停止当前的识别
|
||||
if (recognition) {
|
||||
try {
|
||||
recognition.stop();
|
||||
} catch (e) {
|
||||
console.error('[Browser Page] Error stopping recognition during reset:', e);
|
||||
}
|
||||
}
|
||||
|
||||
// 强制设置为null,丢弃所有后续结果
|
||||
recognition = null;
|
||||
|
||||
// 通知服务器已重置
|
||||
if (ws.readyState === WebSocket.OPEN) {
|
||||
ws.send(JSON.stringify({ type: 'status', message: 'reset_complete' }));
|
||||
}
|
||||
|
||||
updateStatus("语音识别已重置,等待新指令。");
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
123
public/asr-server/embedded.js
Normal file
123
public/asr-server/embedded.js
Normal file
@ -0,0 +1,123 @@
|
||||
/**
|
||||
* 内置的ASR服务器模块
|
||||
* 这个文件可以直接在Electron中运行,不需要外部依赖
|
||||
*/
|
||||
|
||||
// 使用Electron内置的Node.js模块
|
||||
const http = require('http')
|
||||
const path = require('path')
|
||||
const fs = require('fs')
|
||||
|
||||
// 输出环境信息
|
||||
console.log('ASR Server (Embedded) starting...')
|
||||
console.log('Node.js version:', process.version)
|
||||
console.log('Current directory:', __dirname)
|
||||
console.log('Current working directory:', process.cwd())
|
||||
console.log('Command line arguments:', process.argv)
|
||||
|
||||
// 创建HTTP服务器
|
||||
const server = http.createServer((req, res) => {
|
||||
try {
|
||||
if (req.url === '/' || req.url === '/index.html') {
|
||||
// 尝试多个可能的路径
|
||||
const possiblePaths = [
|
||||
// 当前目录
|
||||
path.join(__dirname, 'index.html'),
|
||||
// 上级目录
|
||||
path.join(__dirname, '..', 'index.html'),
|
||||
// 应用根目录
|
||||
path.join(process.cwd(), 'index.html')
|
||||
]
|
||||
|
||||
console.log('Possible index.html paths:', possiblePaths)
|
||||
|
||||
// 查找第一个存在的文件
|
||||
let indexPath = null
|
||||
for (const p of possiblePaths) {
|
||||
try {
|
||||
if (fs.existsSync(p)) {
|
||||
indexPath = p
|
||||
console.log(`Found index.html at: ${p}`)
|
||||
break
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(`Error checking existence of ${p}:`, e)
|
||||
}
|
||||
}
|
||||
|
||||
if (indexPath) {
|
||||
// 读取文件内容并发送
|
||||
fs.readFile(indexPath, (err, data) => {
|
||||
if (err) {
|
||||
console.error('Error reading index.html:', err)
|
||||
res.writeHead(500)
|
||||
res.end('Error reading index.html')
|
||||
return
|
||||
}
|
||||
|
||||
res.writeHead(200, { 'Content-Type': 'text/html' })
|
||||
res.end(data)
|
||||
})
|
||||
} else {
|
||||
// 如果找不到文件,返回一个简单的HTML页面
|
||||
console.error('Could not find index.html, serving fallback page')
|
||||
res.writeHead(200, { 'Content-Type': 'text/html' })
|
||||
res.end(`
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>ASR Server</title>
|
||||
<style>
|
||||
body { font-family: sans-serif; padding: 2em; }
|
||||
h1 { color: #333; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>ASR Server is running</h1>
|
||||
<p>This is a fallback page because the index.html file could not be found.</p>
|
||||
<p>Server is running at: http://localhost:34515</p>
|
||||
<p>Current directory: ${__dirname}</p>
|
||||
<p>Working directory: ${process.cwd()}</p>
|
||||
</body>
|
||||
</html>
|
||||
`)
|
||||
}
|
||||
} else {
|
||||
// 处理其他请求
|
||||
res.writeHead(404)
|
||||
res.end('Not found')
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error handling request:', error)
|
||||
res.writeHead(500)
|
||||
res.end('Server error')
|
||||
}
|
||||
})
|
||||
|
||||
// 添加进程错误处理
|
||||
process.on('uncaughtException', (error) => {
|
||||
console.error('[Server] Uncaught exception:', error)
|
||||
// 不立即退出,给日志输出的时间
|
||||
setTimeout(() => process.exit(1), 1000)
|
||||
})
|
||||
|
||||
process.on('unhandledRejection', (reason, promise) => {
|
||||
console.error('[Server] Unhandled rejection at:', promise, 'reason:', reason)
|
||||
})
|
||||
|
||||
// 尝试启动服务器
|
||||
try {
|
||||
const port = 34515
|
||||
server.listen(port, () => {
|
||||
console.log(`[Server] Server running at http://localhost:${port}`)
|
||||
})
|
||||
|
||||
// 处理服务器错误
|
||||
server.on('error', (error) => {
|
||||
console.error(`[Server] Failed to start server:`, error)
|
||||
process.exit(1) // Exit if server fails to start
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('[Server] Critical error starting server:', error)
|
||||
process.exit(1)
|
||||
}
|
||||
@ -4,7 +4,7 @@
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Browser ASR (External)</title>
|
||||
<title>Cherry Studio ASR</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: sans-serif;
|
||||
@ -36,7 +36,51 @@
|
||||
<script>
|
||||
const statusDiv = document.getElementById('status');
|
||||
const resultDiv = document.getElementById('result');
|
||||
const ws = new WebSocket('ws://localhost:8080'); // Use the defined port
|
||||
// 尝试连接到WebSocket服务器
|
||||
let ws;
|
||||
let reconnectAttempts = 0;
|
||||
const maxReconnectAttempts = 5;
|
||||
const reconnectInterval = 2000; // 2秒
|
||||
|
||||
function connectWebSocket() {
|
||||
try {
|
||||
ws = new WebSocket('ws://localhost:34515');
|
||||
|
||||
ws.onopen = () => {
|
||||
reconnectAttempts = 0;
|
||||
updateStatus('已连接到服务器,等待指令...');
|
||||
ws.send(JSON.stringify({ type: 'identify', role: 'browser' }));
|
||||
};
|
||||
|
||||
ws.onmessage = handleMessage;
|
||||
|
||||
ws.onerror = (error) => {
|
||||
console.error('[Browser Page] WebSocket Error:', error);
|
||||
updateStatus('WebSocket 连接错误!请检查服务器是否运行。');
|
||||
};
|
||||
|
||||
ws.onclose = () => {
|
||||
console.log('[Browser Page] WebSocket Connection Closed');
|
||||
updateStatus('与服务器断开连接。尝试重新连接...');
|
||||
stopRecognition();
|
||||
|
||||
// 尝试重新连接
|
||||
if (reconnectAttempts < maxReconnectAttempts) {
|
||||
reconnectAttempts++;
|
||||
updateStatus(`与服务器断开连接。尝试重新连接 (${reconnectAttempts}/${maxReconnectAttempts})...`);
|
||||
setTimeout(connectWebSocket, reconnectInterval);
|
||||
} else {
|
||||
updateStatus('无法连接到服务器。请刷新页面或重启应用。');
|
||||
}
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('[Browser Page] Error creating WebSocket:', error);
|
||||
updateStatus('创建WebSocket连接时出错。请刷新页面或重启应用。');
|
||||
}
|
||||
}
|
||||
|
||||
// 初始连接
|
||||
connectWebSocket();
|
||||
let recognition = null;
|
||||
const SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
|
||||
|
||||
@ -45,12 +89,7 @@
|
||||
statusDiv.textContent = message;
|
||||
}
|
||||
|
||||
ws.onopen = () => {
|
||||
updateStatus('已连接到服务器,等待指令...');
|
||||
ws.send(JSON.stringify({ type: 'identify', role: 'browser' }));
|
||||
};
|
||||
|
||||
ws.onmessage = (event) => {
|
||||
function handleMessage(event) {
|
||||
let data;
|
||||
try {
|
||||
data = JSON.parse(event.data);
|
||||
@ -64,21 +103,15 @@
|
||||
startRecognition();
|
||||
} else if (data.type === 'stop') {
|
||||
stopRecognition();
|
||||
} else if (data.type === 'reset') {
|
||||
// 强制重置语音识别
|
||||
forceResetRecognition();
|
||||
} else {
|
||||
console.warn('[Browser Page] Received unknown command type:', data.type);
|
||||
}
|
||||
};
|
||||
|
||||
ws.onerror = (error) => {
|
||||
console.error('[Browser Page] WebSocket Error:', error);
|
||||
updateStatus('WebSocket 连接错误!请检查服务器是否运行。');
|
||||
};
|
||||
|
||||
ws.onclose = () => {
|
||||
console.log('[Browser Page] WebSocket Connection Closed');
|
||||
updateStatus('与服务器断开连接。请刷新页面或重启服务器。');
|
||||
stopRecognition();
|
||||
};
|
||||
|
||||
function setupRecognition() {
|
||||
if (!SpeechRecognition) {
|
||||
@ -94,6 +127,16 @@
|
||||
recognition.lang = 'zh-CN';
|
||||
recognition.continuous = true;
|
||||
recognition.interimResults = true;
|
||||
// 增加以下设置提高语音识别的可靠性
|
||||
recognition.maxAlternatives = 3; // 返回多个可能的识别结果
|
||||
// 设置较短的语音识别时间,使用户能更快地看到结果
|
||||
// 注意:这个属性不是标准的,可能不是所有浏览器都支持
|
||||
try {
|
||||
// @ts-ignore
|
||||
recognition.audioStart = 0.1; // 尝试设置较低的起始音量阈值
|
||||
} catch (e) {
|
||||
console.log('[Browser Page] audioStart property not supported');
|
||||
}
|
||||
|
||||
recognition.onstart = () => {
|
||||
updateStatus("🎤 正在识别...");
|
||||
@ -101,40 +144,128 @@
|
||||
};
|
||||
|
||||
recognition.onresult = (event) => {
|
||||
console.log('[Browser Page] Recognition result event:', event);
|
||||
|
||||
let interim_transcript = '';
|
||||
let final_transcript = '';
|
||||
|
||||
// 输出识别结果的详细信息便于调试
|
||||
for (let i = event.resultIndex; i < event.results.length; ++i) {
|
||||
const confidence = event.results[i][0].confidence;
|
||||
console.log(`[Browser Page] Result ${i}: ${event.results[i][0].transcript} (Confidence: ${confidence.toFixed(2)})`);
|
||||
|
||||
if (event.results[i].isFinal) {
|
||||
final_transcript += event.results[i][0].transcript;
|
||||
} else {
|
||||
interim_transcript += event.results[i][0].transcript;
|
||||
}
|
||||
}
|
||||
|
||||
const resultText = final_transcript || interim_transcript;
|
||||
resultDiv.textContent = resultText;
|
||||
|
||||
// 更新状态显示
|
||||
if (resultText) {
|
||||
updateStatus(`🎤 正在识别... (已捕捉到语音)`);
|
||||
}
|
||||
|
||||
if (ws.readyState === WebSocket.OPEN) {
|
||||
console.log(`[Browser Page] Sending ${final_transcript ? 'final' : 'interim'} result to server:`, resultText);
|
||||
ws.send(JSON.stringify({ type: 'result', data: { text: resultText, isFinal: !!final_transcript } }));
|
||||
}
|
||||
};
|
||||
|
||||
recognition.onerror = (event) => {
|
||||
console.error(`[Browser Page] SpeechRecognition Error - Type: ${event.error}, Message: ${event.message}`);
|
||||
updateStatus(`识别错误: ${event.error}`);
|
||||
|
||||
// 根据错误类型提供更友好的错误提示
|
||||
let errorMessage = '';
|
||||
switch (event.error) {
|
||||
case 'no-speech':
|
||||
errorMessage = '未检测到语音,请确保麦克风工作正常并尝试说话。';
|
||||
// 尝试重新启动语音识别
|
||||
setTimeout(() => {
|
||||
if (recognition) {
|
||||
try {
|
||||
recognition.start();
|
||||
console.log('[Browser Page] Restarting recognition after no-speech error');
|
||||
} catch (e) {
|
||||
console.error('[Browser Page] Failed to restart recognition:', e);
|
||||
}
|
||||
}
|
||||
}, 1000);
|
||||
break;
|
||||
case 'audio-capture':
|
||||
errorMessage = '无法捕获音频,请确保麦克风已连接并已授权。';
|
||||
break;
|
||||
case 'not-allowed':
|
||||
errorMessage = '浏览器不允许使用麦克风,请检查权限设置。';
|
||||
break;
|
||||
case 'network':
|
||||
errorMessage = '网络错误导致语音识别失败。';
|
||||
break;
|
||||
case 'aborted':
|
||||
errorMessage = '语音识别被用户或系统中止。';
|
||||
break;
|
||||
default:
|
||||
errorMessage = `识别错误: ${event.error}`;
|
||||
}
|
||||
|
||||
updateStatus(`错误: ${errorMessage}`);
|
||||
|
||||
if (ws.readyState === WebSocket.OPEN) {
|
||||
ws.send(JSON.stringify({ type: 'error', data: { error: event.error, message: event.message || `Recognition error: ${event.error}` } }));
|
||||
ws.send(JSON.stringify({
|
||||
type: 'error',
|
||||
data: {
|
||||
error: event.error,
|
||||
message: errorMessage || event.message || `Recognition error: ${event.error}`
|
||||
}
|
||||
}));
|
||||
}
|
||||
};
|
||||
|
||||
recognition.onend = () => {
|
||||
console.log('[Browser Page] SpeechRecognition ended.');
|
||||
if (!statusDiv.textContent.includes('错误') && !statusDiv.textContent.includes('停止')) {
|
||||
|
||||
// 检查是否是由于错误或用户手动停止导致的结束
|
||||
const isErrorOrStopped = statusDiv.textContent.includes('错误') || statusDiv.textContent.includes('停止');
|
||||
|
||||
if (!isErrorOrStopped) {
|
||||
// 如果不是由于错误或手动停止,则自动重新启动语音识别
|
||||
updateStatus("识别暂停,正在重新启动...");
|
||||
|
||||
// 保存当前的recognition对象
|
||||
const currentRecognition = recognition;
|
||||
|
||||
// 尝试重新启动语音识别
|
||||
setTimeout(() => {
|
||||
try {
|
||||
if (currentRecognition && currentRecognition === recognition) {
|
||||
currentRecognition.start();
|
||||
console.log('[Browser Page] Automatically restarting recognition');
|
||||
} else {
|
||||
// 如果recognition对象已经变化,重新创建一个
|
||||
setupRecognition();
|
||||
if (recognition) {
|
||||
recognition.start();
|
||||
console.log('[Browser Page] Created new recognition instance and started');
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('[Browser Page] Failed to restart recognition:', e);
|
||||
updateStatus("识别已停止。等待指令...");
|
||||
}
|
||||
}, 300);
|
||||
} else {
|
||||
updateStatus("识别已停止。等待指令...");
|
||||
|
||||
if (ws.readyState === WebSocket.OPEN) {
|
||||
ws.send(JSON.stringify({ type: 'status', message: 'stopped' }));
|
||||
}
|
||||
|
||||
// 只有在手动停止或错误时才重置recognition对象
|
||||
recognition = null;
|
||||
}
|
||||
if (ws.readyState === WebSocket.OPEN) {
|
||||
ws.send(JSON.stringify({ type: 'status', message: 'stopped' }));
|
||||
}
|
||||
recognition = null;
|
||||
};
|
||||
return true;
|
||||
}
|
||||
@ -144,6 +275,10 @@
|
||||
updateStatus('错误:浏览器不支持 Web Speech API。');
|
||||
return;
|
||||
}
|
||||
|
||||
// 显示正在准备的状态
|
||||
updateStatus('正在准备麦克风...');
|
||||
|
||||
if (recognition) {
|
||||
console.log('[Browser Page] Recognition already exists, stopping first.');
|
||||
stopRecognition();
|
||||
@ -153,20 +288,88 @@
|
||||
|
||||
console.log('[Browser Page] Attempting to start recognition...');
|
||||
try {
|
||||
navigator.mediaDevices.getUserMedia({ audio: true })
|
||||
// 设置更长的超时时间,确保有足够的时间获取麦克风权限
|
||||
const micPermissionTimeout = setTimeout(() => {
|
||||
updateStatus('获取麦克风权限超时,请刷新页面重试。');
|
||||
}, 10000); // 10秒超时
|
||||
|
||||
navigator.mediaDevices.getUserMedia({
|
||||
audio: {
|
||||
echoCancellation: true,
|
||||
noiseSuppression: true,
|
||||
autoGainControl: true
|
||||
}
|
||||
})
|
||||
.then(stream => {
|
||||
clearTimeout(micPermissionTimeout);
|
||||
console.log('[Browser Page] Microphone access granted.');
|
||||
stream.getTracks().forEach(track => track.stop());
|
||||
|
||||
// 检查麦克风音量级别
|
||||
const audioContext = new AudioContext();
|
||||
const analyser = audioContext.createAnalyser();
|
||||
const microphone = audioContext.createMediaStreamSource(stream);
|
||||
const javascriptNode = audioContext.createScriptProcessor(2048, 1, 1);
|
||||
|
||||
analyser.smoothingTimeConstant = 0.8;
|
||||
analyser.fftSize = 1024;
|
||||
|
||||
microphone.connect(analyser);
|
||||
analyser.connect(javascriptNode);
|
||||
javascriptNode.connect(audioContext.destination);
|
||||
|
||||
javascriptNode.onaudioprocess = function () {
|
||||
const array = new Uint8Array(analyser.frequencyBinCount);
|
||||
analyser.getByteFrequencyData(array);
|
||||
let values = 0;
|
||||
|
||||
const length = array.length;
|
||||
for (let i = 0; i < length; i++) {
|
||||
values += (array[i]);
|
||||
}
|
||||
|
||||
const average = values / length;
|
||||
console.log('[Browser Page] Microphone volume level:', average);
|
||||
|
||||
// 如果音量太低,显示提示
|
||||
if (average < 5) {
|
||||
updateStatus('麦克风音量很低,请说话或检查麦克风设置。');
|
||||
} else {
|
||||
updateStatus('🎤 正在识别...');
|
||||
}
|
||||
|
||||
// 只检查一次就断开连接
|
||||
microphone.disconnect();
|
||||
analyser.disconnect();
|
||||
javascriptNode.disconnect();
|
||||
};
|
||||
|
||||
// 释放测试用的音频流
|
||||
setTimeout(() => {
|
||||
stream.getTracks().forEach(track => track.stop());
|
||||
audioContext.close();
|
||||
}, 1000);
|
||||
|
||||
// 启动语音识别
|
||||
if (recognition) {
|
||||
recognition.start();
|
||||
updateStatus('🎤 正在识别...');
|
||||
} else {
|
||||
updateStatus('错误:Recognition 实例丢失。');
|
||||
console.error('[Browser Page] Recognition instance lost before start.');
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
clearTimeout(micPermissionTimeout);
|
||||
console.error('[Browser Page] Microphone access error:', err);
|
||||
updateStatus(`错误: 无法访问麦克风 (${err.name})`);
|
||||
|
||||
let errorMsg = `无法访问麦克风 (${err.name})`;
|
||||
if (err.name === 'NotAllowedError') {
|
||||
errorMsg = '麦克风访问被拒绝。请在浏览器设置中允许麦克风访问权限。';
|
||||
} else if (err.name === 'NotFoundError') {
|
||||
errorMsg = '未找到麦克风设备。请确保麦克风已连接。';
|
||||
}
|
||||
|
||||
updateStatus(`错误: ${errorMsg}`);
|
||||
recognition = null;
|
||||
});
|
||||
} catch (e) {
|
||||
@ -192,6 +395,30 @@
|
||||
updateStatus("识别未运行。");
|
||||
}
|
||||
}
|
||||
|
||||
function forceResetRecognition() {
|
||||
console.log('[Browser Page] Force resetting recognition...');
|
||||
updateStatus("强制重置语音识别...");
|
||||
|
||||
// 先尝试停止当前的识别
|
||||
if (recognition) {
|
||||
try {
|
||||
recognition.stop();
|
||||
} catch (e) {
|
||||
console.error('[Browser Page] Error stopping recognition during reset:', e);
|
||||
}
|
||||
}
|
||||
|
||||
// 强制设置为null,丢弃所有后续结果
|
||||
recognition = null;
|
||||
|
||||
// 通知服务器已重置
|
||||
if (ws.readyState === WebSocket.OPEN) {
|
||||
ws.send(JSON.stringify({ type: 'status', message: 'reset_complete' }));
|
||||
}
|
||||
|
||||
updateStatus("语音识别已重置,等待新指令。");
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
|
||||
|
||||
854
public/asr-server/package-lock.json
generated
Normal file
854
public/asr-server/package-lock.json
generated
Normal file
@ -0,0 +1,854 @@
|
||||
{
|
||||
"name": "cherry-asr-server",
|
||||
"version": "1.0.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "cherry-asr-server",
|
||||
"version": "1.0.0",
|
||||
"dependencies": {
|
||||
"express": "^4.18.2",
|
||||
"ws": "^8.13.0"
|
||||
}
|
||||
},
|
||||
"node_modules/accepts": {
|
||||
"version": "1.3.8",
|
||||
"resolved": "https://registry.npmmirror.com/accepts/-/accepts-1.3.8.tgz",
|
||||
"integrity": "sha512-PYAthTa2m2VKxuvSD3DPC/Gy+U+sOA1LAuT8mkmRuvw+NACSaeXEQ+NHcVF7rONl6qcaxV3Uuemwawk+7+SJLw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"mime-types": "~2.1.34",
|
||||
"negotiator": "0.6.3"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/array-flatten": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmmirror.com/array-flatten/-/array-flatten-1.1.1.tgz",
|
||||
"integrity": "sha512-PCVAQswWemu6UdxsDFFX/+gVeYqKAod3D3UVm91jHwynguOwAvYPhx8nNlM++NqRcK6CxxpUafjmhIdKiHibqg==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/body-parser": {
|
||||
"version": "1.20.3",
|
||||
"resolved": "https://registry.npmmirror.com/body-parser/-/body-parser-1.20.3.tgz",
|
||||
"integrity": "sha512-7rAxByjUMqQ3/bHJy7D6OGXvx/MMc4IqBn/X0fcM1QUcAItpZrBEYhWGem+tzXH90c+G01ypMcYJBO9Y30203g==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"bytes": "3.1.2",
|
||||
"content-type": "~1.0.5",
|
||||
"debug": "2.6.9",
|
||||
"depd": "2.0.0",
|
||||
"destroy": "1.2.0",
|
||||
"http-errors": "2.0.0",
|
||||
"iconv-lite": "0.4.24",
|
||||
"on-finished": "2.4.1",
|
||||
"qs": "6.13.0",
|
||||
"raw-body": "2.5.2",
|
||||
"type-is": "~1.6.18",
|
||||
"unpipe": "1.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.8",
|
||||
"npm": "1.2.8000 || >= 1.4.16"
|
||||
}
|
||||
},
|
||||
"node_modules/bytes": {
|
||||
"version": "3.1.2",
|
||||
"resolved": "https://registry.npmmirror.com/bytes/-/bytes-3.1.2.tgz",
|
||||
"integrity": "sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/call-bind-apply-helpers": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmmirror.com/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.2.tgz",
|
||||
"integrity": "sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"es-errors": "^1.3.0",
|
||||
"function-bind": "^1.1.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/call-bound": {
|
||||
"version": "1.0.4",
|
||||
"resolved": "https://registry.npmmirror.com/call-bound/-/call-bound-1.0.4.tgz",
|
||||
"integrity": "sha512-+ys997U96po4Kx/ABpBCqhA9EuxJaQWDQg7295H4hBphv3IZg0boBKuwYpt4YXp6MZ5AmZQnU/tyMTlRpaSejg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"call-bind-apply-helpers": "^1.0.2",
|
||||
"get-intrinsic": "^1.3.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/content-disposition": {
|
||||
"version": "0.5.4",
|
||||
"resolved": "https://registry.npmmirror.com/content-disposition/-/content-disposition-0.5.4.tgz",
|
||||
"integrity": "sha512-FveZTNuGw04cxlAiWbzi6zTAL/lhehaWbTtgluJh4/E95DqMwTmha3KZN1aAWA8cFIhHzMZUvLevkw5Rqk+tSQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"safe-buffer": "5.2.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/content-type": {
|
||||
"version": "1.0.5",
|
||||
"resolved": "https://registry.npmmirror.com/content-type/-/content-type-1.0.5.tgz",
|
||||
"integrity": "sha512-nTjqfcBFEipKdXCv4YDQWCfmcLZKm81ldF0pAopTvyrFGVbcR6P/VAAd5G7N+0tTr8QqiU0tFadD6FK4NtJwOA==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/cookie": {
|
||||
"version": "0.7.1",
|
||||
"resolved": "https://registry.npmmirror.com/cookie/-/cookie-0.7.1.tgz",
|
||||
"integrity": "sha512-6DnInpx7SJ2AK3+CTUE/ZM0vWTUboZCegxhC2xiIydHR9jNuTAASBrfEpHhiGOZw/nX51bHt6YQl8jsGo4y/0w==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/cookie-signature": {
|
||||
"version": "1.0.6",
|
||||
"resolved": "https://registry.npmmirror.com/cookie-signature/-/cookie-signature-1.0.6.tgz",
|
||||
"integrity": "sha512-QADzlaHc8icV8I7vbaJXJwod9HWYp8uCqf1xa4OfNu1T7JVxQIrUgOWtHdNDtPiywmFbiS12VjotIXLrKM3orQ==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/debug": {
|
||||
"version": "2.6.9",
|
||||
"resolved": "https://registry.npmmirror.com/debug/-/debug-2.6.9.tgz",
|
||||
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"ms": "2.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/depd": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmmirror.com/depd/-/depd-2.0.0.tgz",
|
||||
"integrity": "sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/destroy": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmmirror.com/destroy/-/destroy-1.2.0.tgz",
|
||||
"integrity": "sha512-2sJGJTaXIIaR1w4iJSNoN0hnMY7Gpc/n8D4qSCJw8QqFWXf7cuAgnEHxBpweaVcPevC2l3KpjYCx3NypQQgaJg==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.8",
|
||||
"npm": "1.2.8000 || >= 1.4.16"
|
||||
}
|
||||
},
|
||||
"node_modules/dunder-proto": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmmirror.com/dunder-proto/-/dunder-proto-1.0.1.tgz",
|
||||
"integrity": "sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"call-bind-apply-helpers": "^1.0.1",
|
||||
"es-errors": "^1.3.0",
|
||||
"gopd": "^1.2.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/ee-first": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmmirror.com/ee-first/-/ee-first-1.1.1.tgz",
|
||||
"integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/encodeurl": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmmirror.com/encodeurl/-/encodeurl-2.0.0.tgz",
|
||||
"integrity": "sha512-Q0n9HRi4m6JuGIV1eFlmvJB7ZEVxu93IrMyiMsGC0lrMJMWzRgx6WGquyfQgZVb31vhGgXnfmPNNXmxnOkRBrg==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/es-define-property": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmmirror.com/es-define-property/-/es-define-property-1.0.1.tgz",
|
||||
"integrity": "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/es-errors": {
|
||||
"version": "1.3.0",
|
||||
"resolved": "https://registry.npmmirror.com/es-errors/-/es-errors-1.3.0.tgz",
|
||||
"integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/es-object-atoms": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmmirror.com/es-object-atoms/-/es-object-atoms-1.1.1.tgz",
|
||||
"integrity": "sha512-FGgH2h8zKNim9ljj7dankFPcICIK9Cp5bm+c2gQSYePhpaG5+esrLODihIorn+Pe6FGJzWhXQotPv73jTaldXA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"es-errors": "^1.3.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/escape-html": {
|
||||
"version": "1.0.3",
|
||||
"resolved": "https://registry.npmmirror.com/escape-html/-/escape-html-1.0.3.tgz",
|
||||
"integrity": "sha512-NiSupZ4OeuGwr68lGIeym/ksIZMJodUGOSCZ/FSnTxcrekbvqrgdUxlJOMpijaKZVjAJrWrGs/6Jy8OMuyj9ow==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/etag": {
|
||||
"version": "1.8.1",
|
||||
"resolved": "https://registry.npmmirror.com/etag/-/etag-1.8.1.tgz",
|
||||
"integrity": "sha512-aIL5Fx7mawVa300al2BnEE4iNvo1qETxLrPI/o05L7z6go7fCw1J6EQmbK4FmJ2AS7kgVF/KEZWufBfdClMcPg==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/express": {
|
||||
"version": "4.21.2",
|
||||
"resolved": "https://registry.npmmirror.com/express/-/express-4.21.2.tgz",
|
||||
"integrity": "sha512-28HqgMZAmih1Czt9ny7qr6ek2qddF4FclbMzwhCREB6OFfH+rXAnuNCwo1/wFvrtbgsQDb4kSbX9de9lFbrXnA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"accepts": "~1.3.8",
|
||||
"array-flatten": "1.1.1",
|
||||
"body-parser": "1.20.3",
|
||||
"content-disposition": "0.5.4",
|
||||
"content-type": "~1.0.4",
|
||||
"cookie": "0.7.1",
|
||||
"cookie-signature": "1.0.6",
|
||||
"debug": "2.6.9",
|
||||
"depd": "2.0.0",
|
||||
"encodeurl": "~2.0.0",
|
||||
"escape-html": "~1.0.3",
|
||||
"etag": "~1.8.1",
|
||||
"finalhandler": "1.3.1",
|
||||
"fresh": "0.5.2",
|
||||
"http-errors": "2.0.0",
|
||||
"merge-descriptors": "1.0.3",
|
||||
"methods": "~1.1.2",
|
||||
"on-finished": "2.4.1",
|
||||
"parseurl": "~1.3.3",
|
||||
"path-to-regexp": "0.1.12",
|
||||
"proxy-addr": "~2.0.7",
|
||||
"qs": "6.13.0",
|
||||
"range-parser": "~1.2.1",
|
||||
"safe-buffer": "5.2.1",
|
||||
"send": "0.19.0",
|
||||
"serve-static": "1.16.2",
|
||||
"setprototypeof": "1.2.0",
|
||||
"statuses": "2.0.1",
|
||||
"type-is": "~1.6.18",
|
||||
"utils-merge": "1.0.1",
|
||||
"vary": "~1.1.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.10.0"
|
||||
},
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/express"
|
||||
}
|
||||
},
|
||||
"node_modules/finalhandler": {
|
||||
"version": "1.3.1",
|
||||
"resolved": "https://registry.npmmirror.com/finalhandler/-/finalhandler-1.3.1.tgz",
|
||||
"integrity": "sha512-6BN9trH7bp3qvnrRyzsBz+g3lZxTNZTbVO2EV1CS0WIcDbawYVdYvGflME/9QP0h0pYlCDBCTjYa9nZzMDpyxQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"debug": "2.6.9",
|
||||
"encodeurl": "~2.0.0",
|
||||
"escape-html": "~1.0.3",
|
||||
"on-finished": "2.4.1",
|
||||
"parseurl": "~1.3.3",
|
||||
"statuses": "2.0.1",
|
||||
"unpipe": "~1.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/forwarded": {
|
||||
"version": "0.2.0",
|
||||
"resolved": "https://registry.npmmirror.com/forwarded/-/forwarded-0.2.0.tgz",
|
||||
"integrity": "sha512-buRG0fpBtRHSTCOASe6hD258tEubFoRLb4ZNA6NxMVHNw2gOcwHo9wyablzMzOA5z9xA9L1KNjk/Nt6MT9aYow==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/fresh": {
|
||||
"version": "0.5.2",
|
||||
"resolved": "https://registry.npmmirror.com/fresh/-/fresh-0.5.2.tgz",
|
||||
"integrity": "sha512-zJ2mQYM18rEFOudeV4GShTGIQ7RbzA7ozbU9I/XBpm7kqgMywgmylMwXHxZJmkVoYkna9d2pVXVXPdYTP9ej8Q==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/function-bind": {
|
||||
"version": "1.1.2",
|
||||
"resolved": "https://registry.npmmirror.com/function-bind/-/function-bind-1.1.2.tgz",
|
||||
"integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==",
|
||||
"license": "MIT",
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/get-intrinsic": {
|
||||
"version": "1.3.0",
|
||||
"resolved": "https://registry.npmmirror.com/get-intrinsic/-/get-intrinsic-1.3.0.tgz",
|
||||
"integrity": "sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"call-bind-apply-helpers": "^1.0.2",
|
||||
"es-define-property": "^1.0.1",
|
||||
"es-errors": "^1.3.0",
|
||||
"es-object-atoms": "^1.1.1",
|
||||
"function-bind": "^1.1.2",
|
||||
"get-proto": "^1.0.1",
|
||||
"gopd": "^1.2.0",
|
||||
"has-symbols": "^1.1.0",
|
||||
"hasown": "^2.0.2",
|
||||
"math-intrinsics": "^1.1.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/get-proto": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmmirror.com/get-proto/-/get-proto-1.0.1.tgz",
|
||||
"integrity": "sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"dunder-proto": "^1.0.1",
|
||||
"es-object-atoms": "^1.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/gopd": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmmirror.com/gopd/-/gopd-1.2.0.tgz",
|
||||
"integrity": "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/has-symbols": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmmirror.com/has-symbols/-/has-symbols-1.1.0.tgz",
|
||||
"integrity": "sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/hasown": {
|
||||
"version": "2.0.2",
|
||||
"resolved": "https://registry.npmmirror.com/hasown/-/hasown-2.0.2.tgz",
|
||||
"integrity": "sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"function-bind": "^1.1.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/http-errors": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmmirror.com/http-errors/-/http-errors-2.0.0.tgz",
|
||||
"integrity": "sha512-FtwrG/euBzaEjYeRqOgly7G0qviiXoJWnvEH2Z1plBdXgbyjv34pHTSb9zoeHMyDy33+DWy5Wt9Wo+TURtOYSQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"depd": "2.0.0",
|
||||
"inherits": "2.0.4",
|
||||
"setprototypeof": "1.2.0",
|
||||
"statuses": "2.0.1",
|
||||
"toidentifier": "1.0.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/iconv-lite": {
|
||||
"version": "0.4.24",
|
||||
"resolved": "https://registry.npmmirror.com/iconv-lite/-/iconv-lite-0.4.24.tgz",
|
||||
"integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"safer-buffer": ">= 2.1.2 < 3"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.10.0"
|
||||
}
|
||||
},
|
||||
"node_modules/inherits": {
|
||||
"version": "2.0.4",
|
||||
"resolved": "https://registry.npmmirror.com/inherits/-/inherits-2.0.4.tgz",
|
||||
"integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==",
|
||||
"license": "ISC"
|
||||
},
|
||||
"node_modules/ipaddr.js": {
|
||||
"version": "1.9.1",
|
||||
"resolved": "https://registry.npmmirror.com/ipaddr.js/-/ipaddr.js-1.9.1.tgz",
|
||||
"integrity": "sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.10"
|
||||
}
|
||||
},
|
||||
"node_modules/math-intrinsics": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmmirror.com/math-intrinsics/-/math-intrinsics-1.1.0.tgz",
|
||||
"integrity": "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/media-typer": {
|
||||
"version": "0.3.0",
|
||||
"resolved": "https://registry.npmmirror.com/media-typer/-/media-typer-0.3.0.tgz",
|
||||
"integrity": "sha512-dq+qelQ9akHpcOl/gUVRTxVIOkAJ1wR3QAvb4RsVjS8oVoFjDGTc679wJYmUmknUF5HwMLOgb5O+a3KxfWapPQ==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/merge-descriptors": {
|
||||
"version": "1.0.3",
|
||||
"resolved": "https://registry.npmmirror.com/merge-descriptors/-/merge-descriptors-1.0.3.tgz",
|
||||
"integrity": "sha512-gaNvAS7TZ897/rVaZ0nMtAyxNyi/pdbjbAwUpFQpN70GqnVfOiXpeUUMKRBmzXaSQ8DdTX4/0ms62r2K+hE6mQ==",
|
||||
"license": "MIT",
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/sindresorhus"
|
||||
}
|
||||
},
|
||||
"node_modules/methods": {
|
||||
"version": "1.1.2",
|
||||
"resolved": "https://registry.npmmirror.com/methods/-/methods-1.1.2.tgz",
|
||||
"integrity": "sha512-iclAHeNqNm68zFtnZ0e+1L2yUIdvzNoauKU4WBA3VvH/vPFieF7qfRlwUZU+DA9P9bPXIS90ulxoUoCH23sV2w==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/mime": {
|
||||
"version": "1.6.0",
|
||||
"resolved": "https://registry.npmmirror.com/mime/-/mime-1.6.0.tgz",
|
||||
"integrity": "sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg==",
|
||||
"license": "MIT",
|
||||
"bin": {
|
||||
"mime": "cli.js"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=4"
|
||||
}
|
||||
},
|
||||
"node_modules/mime-db": {
|
||||
"version": "1.52.0",
|
||||
"resolved": "https://registry.npmmirror.com/mime-db/-/mime-db-1.52.0.tgz",
|
||||
"integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/mime-types": {
|
||||
"version": "2.1.35",
|
||||
"resolved": "https://registry.npmmirror.com/mime-types/-/mime-types-2.1.35.tgz",
|
||||
"integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"mime-db": "1.52.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/ms": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmmirror.com/ms/-/ms-2.0.0.tgz",
|
||||
"integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/negotiator": {
|
||||
"version": "0.6.3",
|
||||
"resolved": "https://registry.npmmirror.com/negotiator/-/negotiator-0.6.3.tgz",
|
||||
"integrity": "sha512-+EUsqGPLsM+j/zdChZjsnX51g4XrHFOIXwfnCVPGlQk/k5giakcKsuxCObBRu6DSm9opw/O6slWbJdghQM4bBg==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/object-inspect": {
|
||||
"version": "1.13.4",
|
||||
"resolved": "https://registry.npmmirror.com/object-inspect/-/object-inspect-1.13.4.tgz",
|
||||
"integrity": "sha512-W67iLl4J2EXEGTbfeHCffrjDfitvLANg0UlX3wFUUSTx92KXRFegMHUVgSqE+wvhAbi4WqjGg9czysTV2Epbew==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/on-finished": {
|
||||
"version": "2.4.1",
|
||||
"resolved": "https://registry.npmmirror.com/on-finished/-/on-finished-2.4.1.tgz",
|
||||
"integrity": "sha512-oVlzkg3ENAhCk2zdv7IJwd/QUD4z2RxRwpkcGY8psCVcCYZNq4wYnVWALHM+brtuJjePWiYF/ClmuDr8Ch5+kg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"ee-first": "1.1.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/parseurl": {
|
||||
"version": "1.3.3",
|
||||
"resolved": "https://registry.npmmirror.com/parseurl/-/parseurl-1.3.3.tgz",
|
||||
"integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/path-to-regexp": {
|
||||
"version": "0.1.12",
|
||||
"resolved": "https://registry.npmmirror.com/path-to-regexp/-/path-to-regexp-0.1.12.tgz",
|
||||
"integrity": "sha512-RA1GjUVMnvYFxuqovrEqZoxxW5NUZqbwKtYz/Tt7nXerk0LbLblQmrsgdeOxV5SFHf0UDggjS/bSeOZwt1pmEQ==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/proxy-addr": {
|
||||
"version": "2.0.7",
|
||||
"resolved": "https://registry.npmmirror.com/proxy-addr/-/proxy-addr-2.0.7.tgz",
|
||||
"integrity": "sha512-llQsMLSUDUPT44jdrU/O37qlnifitDP+ZwrmmZcoSKyLKvtZxpyV0n2/bD/N4tBAAZ/gJEdZU7KMraoK1+XYAg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"forwarded": "0.2.0",
|
||||
"ipaddr.js": "1.9.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.10"
|
||||
}
|
||||
},
|
||||
"node_modules/qs": {
|
||||
"version": "6.13.0",
|
||||
"resolved": "https://registry.npmmirror.com/qs/-/qs-6.13.0.tgz",
|
||||
"integrity": "sha512-+38qI9SOr8tfZ4QmJNplMUxqjbe7LKvvZgWdExBOmd+egZTtjLB67Gu0HRX3u/XOq7UU2Nx6nsjvS16Z9uwfpg==",
|
||||
"license": "BSD-3-Clause",
|
||||
"dependencies": {
|
||||
"side-channel": "^1.0.6"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.6"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/range-parser": {
|
||||
"version": "1.2.1",
|
||||
"resolved": "https://registry.npmmirror.com/range-parser/-/range-parser-1.2.1.tgz",
|
||||
"integrity": "sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/raw-body": {
|
||||
"version": "2.5.2",
|
||||
"resolved": "https://registry.npmmirror.com/raw-body/-/raw-body-2.5.2.tgz",
|
||||
"integrity": "sha512-8zGqypfENjCIqGhgXToC8aB2r7YrBX+AQAfIPs/Mlk+BtPTztOvTS01NRW/3Eh60J+a48lt8qsCzirQ6loCVfA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"bytes": "3.1.2",
|
||||
"http-errors": "2.0.0",
|
||||
"iconv-lite": "0.4.24",
|
||||
"unpipe": "1.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/safe-buffer": {
|
||||
"version": "5.2.1",
|
||||
"resolved": "https://registry.npmmirror.com/safe-buffer/-/safe-buffer-5.2.1.tgz",
|
||||
"integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==",
|
||||
"funding": [
|
||||
{
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/feross"
|
||||
},
|
||||
{
|
||||
"type": "patreon",
|
||||
"url": "https://www.patreon.com/feross"
|
||||
},
|
||||
{
|
||||
"type": "consulting",
|
||||
"url": "https://feross.org/support"
|
||||
}
|
||||
],
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/safer-buffer": {
|
||||
"version": "2.1.2",
|
||||
"resolved": "https://registry.npmmirror.com/safer-buffer/-/safer-buffer-2.1.2.tgz",
|
||||
"integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/send": {
|
||||
"version": "0.19.0",
|
||||
"resolved": "https://registry.npmmirror.com/send/-/send-0.19.0.tgz",
|
||||
"integrity": "sha512-dW41u5VfLXu8SJh5bwRmyYUbAoSB3c9uQh6L8h/KtsFREPWpbX1lrljJo186Jc4nmci/sGUZ9a0a0J2zgfq2hw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"debug": "2.6.9",
|
||||
"depd": "2.0.0",
|
||||
"destroy": "1.2.0",
|
||||
"encodeurl": "~1.0.2",
|
||||
"escape-html": "~1.0.3",
|
||||
"etag": "~1.8.1",
|
||||
"fresh": "0.5.2",
|
||||
"http-errors": "2.0.0",
|
||||
"mime": "1.6.0",
|
||||
"ms": "2.1.3",
|
||||
"on-finished": "2.4.1",
|
||||
"range-parser": "~1.2.1",
|
||||
"statuses": "2.0.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.8.0"
|
||||
}
|
||||
},
|
||||
"node_modules/send/node_modules/encodeurl": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmmirror.com/encodeurl/-/encodeurl-1.0.2.tgz",
|
||||
"integrity": "sha512-TPJXq8JqFaVYm2CWmPvnP2Iyo4ZSM7/QKcSmuMLDObfpH5fi7RUGmd/rTDf+rut/saiDiQEeVTNgAmJEdAOx0w==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/send/node_modules/ms": {
|
||||
"version": "2.1.3",
|
||||
"resolved": "https://registry.npmmirror.com/ms/-/ms-2.1.3.tgz",
|
||||
"integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/serve-static": {
|
||||
"version": "1.16.2",
|
||||
"resolved": "https://registry.npmmirror.com/serve-static/-/serve-static-1.16.2.tgz",
|
||||
"integrity": "sha512-VqpjJZKadQB/PEbEwvFdO43Ax5dFBZ2UECszz8bQ7pi7wt//PWe1P6MN7eCnjsatYtBT6EuiClbjSWP2WrIoTw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"encodeurl": "~2.0.0",
|
||||
"escape-html": "~1.0.3",
|
||||
"parseurl": "~1.3.3",
|
||||
"send": "0.19.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.8.0"
|
||||
}
|
||||
},
|
||||
"node_modules/setprototypeof": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmmirror.com/setprototypeof/-/setprototypeof-1.2.0.tgz",
|
||||
"integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==",
|
||||
"license": "ISC"
|
||||
},
|
||||
"node_modules/side-channel": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmmirror.com/side-channel/-/side-channel-1.1.0.tgz",
|
||||
"integrity": "sha512-ZX99e6tRweoUXqR+VBrslhda51Nh5MTQwou5tnUDgbtyM0dBgmhEDtWGP/xbKn6hqfPRHujUNwz5fy/wbbhnpw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"es-errors": "^1.3.0",
|
||||
"object-inspect": "^1.13.3",
|
||||
"side-channel-list": "^1.0.0",
|
||||
"side-channel-map": "^1.0.1",
|
||||
"side-channel-weakmap": "^1.0.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/side-channel-list": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmmirror.com/side-channel-list/-/side-channel-list-1.0.0.tgz",
|
||||
"integrity": "sha512-FCLHtRD/gnpCiCHEiJLOwdmFP+wzCmDEkc9y7NsYxeF4u7Btsn1ZuwgwJGxImImHicJArLP4R0yX4c2KCrMrTA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"es-errors": "^1.3.0",
|
||||
"object-inspect": "^1.13.3"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/side-channel-map": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmmirror.com/side-channel-map/-/side-channel-map-1.0.1.tgz",
|
||||
"integrity": "sha512-VCjCNfgMsby3tTdo02nbjtM/ewra6jPHmpThenkTYh8pG9ucZ/1P8So4u4FGBek/BjpOVsDCMoLA/iuBKIFXRA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"call-bound": "^1.0.2",
|
||||
"es-errors": "^1.3.0",
|
||||
"get-intrinsic": "^1.2.5",
|
||||
"object-inspect": "^1.13.3"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/side-channel-weakmap": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmmirror.com/side-channel-weakmap/-/side-channel-weakmap-1.0.2.tgz",
|
||||
"integrity": "sha512-WPS/HvHQTYnHisLo9McqBHOJk2FkHO/tlpvldyrnem4aeQp4hai3gythswg6p01oSoTl58rcpiFAjF2br2Ak2A==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"call-bound": "^1.0.2",
|
||||
"es-errors": "^1.3.0",
|
||||
"get-intrinsic": "^1.2.5",
|
||||
"object-inspect": "^1.13.3",
|
||||
"side-channel-map": "^1.0.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/statuses": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmmirror.com/statuses/-/statuses-2.0.1.tgz",
|
||||
"integrity": "sha512-RwNA9Z/7PrK06rYLIzFMlaF+l73iwpzsqRIFgbMLbTcLD6cOao82TaWefPXQvB2fOC4AjuYSEndS7N/mTCbkdQ==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/toidentifier": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmmirror.com/toidentifier/-/toidentifier-1.0.1.tgz",
|
||||
"integrity": "sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/type-is": {
|
||||
"version": "1.6.18",
|
||||
"resolved": "https://registry.npmmirror.com/type-is/-/type-is-1.6.18.tgz",
|
||||
"integrity": "sha512-TkRKr9sUTxEH8MdfuCSP7VizJyzRNMjj2J2do2Jr3Kym598JVdEksuzPQCnlFPW4ky9Q+iA+ma9BGm06XQBy8g==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"media-typer": "0.3.0",
|
||||
"mime-types": "~2.1.24"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/unpipe": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmmirror.com/unpipe/-/unpipe-1.0.0.tgz",
|
||||
"integrity": "sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/utils-merge": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmmirror.com/utils-merge/-/utils-merge-1.0.1.tgz",
|
||||
"integrity": "sha512-pMZTvIkT1d+TFGvDOqodOclx0QWkkgi6Tdoa8gC8ffGAAqz9pzPTZWAybbsHHoED/ztMtkv/VoYTYyShUn81hA==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.4.0"
|
||||
}
|
||||
},
|
||||
"node_modules/vary": {
|
||||
"version": "1.1.2",
|
||||
"resolved": "https://registry.npmmirror.com/vary/-/vary-1.1.2.tgz",
|
||||
"integrity": "sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/ws": {
|
||||
"version": "8.18.1",
|
||||
"resolved": "https://registry.npmmirror.com/ws/-/ws-8.18.1.tgz",
|
||||
"integrity": "sha512-RKW2aJZMXeMxVpnZ6bck+RswznaxmzdULiBr6KY7XkTnW8uvt0iT9H5DkHUChXrc+uurzwa0rVI16n/Xzjdz1w==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=10.0.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"bufferutil": "^4.0.1",
|
||||
"utf-8-validate": ">=5.0.2"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"bufferutil": {
|
||||
"optional": true
|
||||
},
|
||||
"utf-8-validate": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
10
public/asr-server/package.json
Normal file
10
public/asr-server/package.json
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"name": "cherry-asr-server",
|
||||
"version": "1.0.0",
|
||||
"description": "Cherry Studio ASR Server",
|
||||
"main": "server.js",
|
||||
"dependencies": {
|
||||
"express": "^4.18.2",
|
||||
"ws": "^8.13.0"
|
||||
}
|
||||
}
|
||||
@ -1,15 +1,114 @@
|
||||
// 检查依赖项
|
||||
try {
|
||||
console.log('ASR Server starting...')
|
||||
console.log('Node.js version:', process.version)
|
||||
console.log('Current directory:', __dirname)
|
||||
console.log('Current working directory:', process.cwd())
|
||||
console.log('Command line arguments:', process.argv)
|
||||
|
||||
// 检查必要的依赖项
|
||||
const checkDependency = (name) => {
|
||||
try {
|
||||
require(name) // Removed unused variable 'module'
|
||||
console.log(`Successfully loaded dependency: ${name}`)
|
||||
return true
|
||||
} catch (error) {
|
||||
console.error(`Failed to load dependency: ${name}`, error.message)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// 检查所有必要的依赖项
|
||||
const dependencies = ['http', 'ws', 'express', 'path', 'fs']
|
||||
const missingDeps = dependencies.filter((dep) => !checkDependency(dep))
|
||||
|
||||
if (missingDeps.length > 0) {
|
||||
console.error(`Missing dependencies: ${missingDeps.join(', ')}. Server cannot start.`)
|
||||
process.exit(1)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error during dependency check:', error)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
// 加载依赖项
|
||||
const http = require('http')
|
||||
const WebSocket = require('ws')
|
||||
const express = require('express')
|
||||
const path = require('path') // Need path module
|
||||
// const fs = require('fs') // Commented out unused import 'fs'
|
||||
|
||||
const app = express()
|
||||
const port = 8080 // Define the port
|
||||
const port = 34515 // Define the port
|
||||
|
||||
// 获取index.html文件的路径
|
||||
function getIndexHtmlPath() {
|
||||
const fs = require('fs')
|
||||
console.log('Current directory:', __dirname)
|
||||
console.log('Current working directory:', process.cwd())
|
||||
|
||||
// 尝试多个可能的路径
|
||||
const possiblePaths = [
|
||||
// 开发环境路径
|
||||
path.join(__dirname, 'index.html'),
|
||||
// 当前目录
|
||||
path.join(process.cwd(), 'index.html'),
|
||||
// 相对于可执行文件的路径
|
||||
path.join(path.dirname(process.execPath), 'index.html'),
|
||||
// 相对于可执行文件的上级目录的路径
|
||||
path.join(path.dirname(path.dirname(process.execPath)), 'index.html'),
|
||||
// 相对于可执行文件的resources目录的路径
|
||||
path.join(path.dirname(process.execPath), 'resources', 'index.html'),
|
||||
// 相对于可执行文件的resources/asr-server目录的路径
|
||||
path.join(path.dirname(process.execPath), 'resources', 'asr-server', 'index.html'),
|
||||
// 相对于可执行文件的asr-server目录的路径
|
||||
path.join(path.dirname(process.execPath), 'asr-server', 'index.html'),
|
||||
// 如果是pkg打包环境
|
||||
process.pkg ? path.join(path.dirname(process.execPath), 'index.html') : null
|
||||
].filter(Boolean) // 过滤掉null值
|
||||
|
||||
console.log('Possible index.html paths:', possiblePaths)
|
||||
|
||||
// 检查每个路径,返回第一个存在的文件
|
||||
for (const p of possiblePaths) {
|
||||
try {
|
||||
if (fs.existsSync(p)) {
|
||||
console.log(`Found index.html at: ${p}`)
|
||||
return p
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(`Error checking existence of ${p}:`, e)
|
||||
}
|
||||
}
|
||||
|
||||
// 如果没有找到文件,返回默认路径并记录错误
|
||||
console.error('Could not find index.html in any of the expected locations')
|
||||
return path.join(__dirname, 'index.html') // 返回默认路径,即使它可能不存在
|
||||
}
|
||||
|
||||
// 提供网页给浏览器
|
||||
app.get('/', (req, res) => {
|
||||
// Use path.join for cross-platform compatibility
|
||||
res.sendFile(path.join(__dirname, 'index.html'))
|
||||
try {
|
||||
const indexPath = getIndexHtmlPath()
|
||||
console.log(`Serving index.html from: ${indexPath}`)
|
||||
|
||||
// 检查文件是否存在
|
||||
const fs = require('fs')
|
||||
if (!fs.existsSync(indexPath)) {
|
||||
console.error(`Error: index.html not found at ${indexPath}`)
|
||||
return res.status(404).send(`Error: index.html not found at ${indexPath}. <br>Please check the server logs.`)
|
||||
}
|
||||
|
||||
res.sendFile(indexPath, (err) => {
|
||||
if (err) {
|
||||
console.error('Error sending index.html:', err)
|
||||
res.status(500).send(`Error serving index.html: ${err.message}`)
|
||||
}
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('Error in route handler:', error)
|
||||
res.status(500).send(`Server error: ${error.message}`)
|
||||
}
|
||||
})
|
||||
|
||||
const server = http.createServer(app)
|
||||
@ -98,6 +197,13 @@ wss.on('connection', (ws) => {
|
||||
} else {
|
||||
console.log('[Server] Cannot relay STOP: Browser not connected')
|
||||
}
|
||||
} else if (data.type === 'reset' && ws === electronConnection) {
|
||||
if (browserConnection && browserConnection.readyState === WebSocket.OPEN) {
|
||||
console.log('[Server] Relaying RESET command to browser')
|
||||
browserConnection.send(JSON.stringify({ type: 'reset' }))
|
||||
} else {
|
||||
console.log('[Server] Cannot relay RESET: Browser not connected')
|
||||
}
|
||||
}
|
||||
// 浏览器发送识别结果
|
||||
else if (data.type === 'result' && ws === browserConnection) {
|
||||
@ -135,12 +241,29 @@ wss.on('connection', (ws) => {
|
||||
})
|
||||
})
|
||||
|
||||
server.listen(port, () => {
|
||||
console.log(`[Server] Server running at http://localhost:${port}`)
|
||||
// 添加进程错误处理
|
||||
process.on('uncaughtException', (error) => {
|
||||
console.error('[Server] Uncaught exception:', error)
|
||||
// 不立即退出,给日志输出的时间
|
||||
setTimeout(() => process.exit(1), 1000)
|
||||
})
|
||||
|
||||
// Handle server errors
|
||||
server.on('error', (error) => {
|
||||
console.error(`[Server] Failed to start server:`, error)
|
||||
process.exit(1) // Exit if server fails to start
|
||||
process.on('unhandledRejection', (reason, promise) => {
|
||||
console.error('[Server] Unhandled rejection at:', promise, 'reason:', reason)
|
||||
})
|
||||
|
||||
// 尝试启动服务器
|
||||
try {
|
||||
server.listen(port, () => {
|
||||
console.log(`[Server] Server running at http://localhost:${port}`)
|
||||
})
|
||||
|
||||
// Handle server errors
|
||||
server.on('error', (error) => {
|
||||
console.error(`[Server] Failed to start server:`, error)
|
||||
process.exit(1) // Exit if server fails to start
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('[Server] Critical error starting server:', error)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
114
public/asr-server/standalone.js
Normal file
114
public/asr-server/standalone.js
Normal file
@ -0,0 +1,114 @@
|
||||
/**
|
||||
* 独立的ASR服务器
|
||||
* 这个文件是一个简化版的server.js,用于在打包后的应用中运行
|
||||
*/
|
||||
|
||||
// 基本依赖
|
||||
const http = require('http')
|
||||
const express = require('express')
|
||||
const path = require('path')
|
||||
const fs = require('fs')
|
||||
|
||||
// 输出环境信息
|
||||
console.log('ASR Server starting...')
|
||||
console.log('Node.js version:', process.version)
|
||||
console.log('Current directory:', __dirname)
|
||||
console.log('Current working directory:', process.cwd())
|
||||
console.log('Command line arguments:', process.argv)
|
||||
|
||||
// 创建Express应用
|
||||
const app = express()
|
||||
const port = 34515
|
||||
|
||||
// 提供静态文件
|
||||
app.use(express.static(__dirname))
|
||||
|
||||
// 提供网页给浏览器
|
||||
app.get('/', (req, res) => {
|
||||
try {
|
||||
// 尝试多个可能的路径
|
||||
const possiblePaths = [
|
||||
// 当前目录
|
||||
path.join(__dirname, 'index.html'),
|
||||
// 上级目录
|
||||
path.join(__dirname, '..', 'index.html'),
|
||||
// 应用根目录
|
||||
path.join(process.cwd(), 'index.html')
|
||||
]
|
||||
|
||||
console.log('Possible index.html paths:', possiblePaths)
|
||||
|
||||
// 查找第一个存在的文件
|
||||
let indexPath = null
|
||||
for (const p of possiblePaths) {
|
||||
try {
|
||||
if (fs.existsSync(p)) {
|
||||
indexPath = p
|
||||
console.log(`Found index.html at: ${p}`)
|
||||
break
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(`Error checking existence of ${p}:`, e)
|
||||
}
|
||||
}
|
||||
|
||||
if (indexPath) {
|
||||
res.sendFile(indexPath)
|
||||
} else {
|
||||
// 如果找不到文件,返回一个简单的HTML页面
|
||||
console.error('Could not find index.html, serving fallback page')
|
||||
res.send(`
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>ASR Server</title>
|
||||
<style>
|
||||
body { font-family: sans-serif; padding: 2em; }
|
||||
h1 { color: #333; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>ASR Server is running</h1>
|
||||
<p>This is a fallback page because the index.html file could not be found.</p>
|
||||
<p>Server is running at: http://localhost:${port}</p>
|
||||
<p>Current directory: ${__dirname}</p>
|
||||
<p>Working directory: ${process.cwd()}</p>
|
||||
</body>
|
||||
</html>
|
||||
`)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error serving index.html:', error)
|
||||
res.status(500).send(`Server error: ${error.message}`)
|
||||
}
|
||||
})
|
||||
|
||||
// 创建HTTP服务器
|
||||
const server = http.createServer(app)
|
||||
|
||||
// 添加进程错误处理
|
||||
process.on('uncaughtException', (error) => {
|
||||
console.error('[Server] Uncaught exception:', error)
|
||||
// 不立即退出,给日志输出的时间
|
||||
setTimeout(() => process.exit(1), 1000)
|
||||
})
|
||||
|
||||
process.on('unhandledRejection', (reason, promise) => {
|
||||
console.error('[Server] Unhandled rejection at:', promise, 'reason:', reason)
|
||||
})
|
||||
|
||||
// 尝试启动服务器
|
||||
try {
|
||||
server.listen(port, () => {
|
||||
console.log(`[Server] Server running at http://localhost:${port}`)
|
||||
})
|
||||
|
||||
// 处理服务器错误
|
||||
server.on('error', (error) => {
|
||||
console.error(`[Server] Failed to start server:`, error)
|
||||
process.exit(1) // Exit if server fails to start
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('[Server] Critical error starting server:', error)
|
||||
process.exit(1)
|
||||
}
|
||||
5
public/asr-server/start-server.bat
Normal file
5
public/asr-server/start-server.bat
Normal file
@ -0,0 +1,5 @@
|
||||
@echo off
|
||||
echo Starting ASR Server...
|
||||
cd /d %~dp0
|
||||
node standalone.js
|
||||
pause
|
||||
123
resources/asr-server/embedded.js
Normal file
123
resources/asr-server/embedded.js
Normal file
@ -0,0 +1,123 @@
|
||||
/**
|
||||
* 内置的ASR服务器模块
|
||||
* 这个文件可以直接在Electron中运行,不需要外部依赖
|
||||
*/
|
||||
|
||||
// 使用Electron内置的Node.js模块
|
||||
const http = require('http')
|
||||
const path = require('path')
|
||||
const fs = require('fs')
|
||||
|
||||
// 输出环境信息
|
||||
console.log('ASR Server (Embedded) starting...')
|
||||
console.log('Node.js version:', process.version)
|
||||
console.log('Current directory:', __dirname)
|
||||
console.log('Current working directory:', process.cwd())
|
||||
console.log('Command line arguments:', process.argv)
|
||||
|
||||
// 创建HTTP服务器
|
||||
const server = http.createServer((req, res) => {
|
||||
try {
|
||||
if (req.url === '/' || req.url === '/index.html') {
|
||||
// 尝试多个可能的路径
|
||||
const possiblePaths = [
|
||||
// 当前目录
|
||||
path.join(__dirname, 'index.html'),
|
||||
// 上级目录
|
||||
path.join(__dirname, '..', 'index.html'),
|
||||
// 应用根目录
|
||||
path.join(process.cwd(), 'index.html')
|
||||
]
|
||||
|
||||
console.log('Possible index.html paths:', possiblePaths)
|
||||
|
||||
// 查找第一个存在的文件
|
||||
let indexPath = null
|
||||
for (const p of possiblePaths) {
|
||||
try {
|
||||
if (fs.existsSync(p)) {
|
||||
indexPath = p
|
||||
console.log(`Found index.html at: ${p}`)
|
||||
break
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(`Error checking existence of ${p}:`, e)
|
||||
}
|
||||
}
|
||||
|
||||
if (indexPath) {
|
||||
// 读取文件内容并发送
|
||||
fs.readFile(indexPath, (err, data) => {
|
||||
if (err) {
|
||||
console.error('Error reading index.html:', err)
|
||||
res.writeHead(500)
|
||||
res.end('Error reading index.html')
|
||||
return
|
||||
}
|
||||
|
||||
res.writeHead(200, { 'Content-Type': 'text/html' })
|
||||
res.end(data)
|
||||
})
|
||||
} else {
|
||||
// 如果找不到文件,返回一个简单的HTML页面
|
||||
console.error('Could not find index.html, serving fallback page')
|
||||
res.writeHead(200, { 'Content-Type': 'text/html' })
|
||||
res.end(`
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>ASR Server</title>
|
||||
<style>
|
||||
body { font-family: sans-serif; padding: 2em; }
|
||||
h1 { color: #333; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>ASR Server is running</h1>
|
||||
<p>This is a fallback page because the index.html file could not be found.</p>
|
||||
<p>Server is running at: http://localhost:34515</p>
|
||||
<p>Current directory: ${__dirname}</p>
|
||||
<p>Working directory: ${process.cwd()}</p>
|
||||
</body>
|
||||
</html>
|
||||
`)
|
||||
}
|
||||
} else {
|
||||
// 处理其他请求
|
||||
res.writeHead(404)
|
||||
res.end('Not found')
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error handling request:', error)
|
||||
res.writeHead(500)
|
||||
res.end('Server error')
|
||||
}
|
||||
})
|
||||
|
||||
// 添加进程错误处理
|
||||
process.on('uncaughtException', (error) => {
|
||||
console.error('[Server] Uncaught exception:', error)
|
||||
// 不立即退出,给日志输出的时间
|
||||
setTimeout(() => process.exit(1), 1000)
|
||||
})
|
||||
|
||||
process.on('unhandledRejection', (reason, promise) => {
|
||||
console.error('[Server] Unhandled rejection at:', promise, 'reason:', reason)
|
||||
})
|
||||
|
||||
// 尝试启动服务器
|
||||
try {
|
||||
const port = 34515
|
||||
server.listen(port, () => {
|
||||
console.log(`[Server] Server running at http://localhost:${port}`)
|
||||
})
|
||||
|
||||
// 处理服务器错误
|
||||
server.on('error', (error) => {
|
||||
console.error(`[Server] Failed to start server:`, error)
|
||||
process.exit(1) // Exit if server fails to start
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('[Server] Critical error starting server:', error)
|
||||
process.exit(1)
|
||||
}
|
||||
425
resources/asr-server/index.html
Normal file
425
resources/asr-server/index.html
Normal file
@ -0,0 +1,425 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Cherry Studio ASR</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: sans-serif;
|
||||
padding: 1em;
|
||||
}
|
||||
|
||||
#status {
|
||||
margin-top: 1em;
|
||||
font-style: italic;
|
||||
color: #555;
|
||||
}
|
||||
|
||||
#result {
|
||||
margin-top: 0.5em;
|
||||
border: 1px solid #ccc;
|
||||
padding: 0.5em;
|
||||
min-height: 50px;
|
||||
background: #f9f9f9;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>浏览器语音识别中继页面</h1>
|
||||
<p>这个页面需要在浏览器中保持打开,以便应用使用其语音识别功能。</p>
|
||||
<div id="status">正在连接到服务器...</div>
|
||||
<div id="result"></div>
|
||||
|
||||
<script>
|
||||
const statusDiv = document.getElementById('status');
|
||||
const resultDiv = document.getElementById('result');
|
||||
// 尝试连接到WebSocket服务器
|
||||
let ws;
|
||||
let reconnectAttempts = 0;
|
||||
const maxReconnectAttempts = 5;
|
||||
const reconnectInterval = 2000; // 2秒
|
||||
|
||||
function connectWebSocket() {
|
||||
try {
|
||||
ws = new WebSocket('ws://localhost:34515');
|
||||
|
||||
ws.onopen = () => {
|
||||
reconnectAttempts = 0;
|
||||
updateStatus('已连接到服务器,等待指令...');
|
||||
ws.send(JSON.stringify({ type: 'identify', role: 'browser' }));
|
||||
};
|
||||
|
||||
ws.onmessage = handleMessage;
|
||||
|
||||
ws.onerror = (error) => {
|
||||
console.error('[Browser Page] WebSocket Error:', error);
|
||||
updateStatus('WebSocket 连接错误!请检查服务器是否运行。');
|
||||
};
|
||||
|
||||
ws.onclose = () => {
|
||||
console.log('[Browser Page] WebSocket Connection Closed');
|
||||
updateStatus('与服务器断开连接。尝试重新连接...');
|
||||
stopRecognition();
|
||||
|
||||
// 尝试重新连接
|
||||
if (reconnectAttempts < maxReconnectAttempts) {
|
||||
reconnectAttempts++;
|
||||
updateStatus(`与服务器断开连接。尝试重新连接 (${reconnectAttempts}/${maxReconnectAttempts})...`);
|
||||
setTimeout(connectWebSocket, reconnectInterval);
|
||||
} else {
|
||||
updateStatus('无法连接到服务器。请刷新页面或重启应用。');
|
||||
}
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('[Browser Page] Error creating WebSocket:', error);
|
||||
updateStatus('创建WebSocket连接时出错。请刷新页面或重启应用。');
|
||||
}
|
||||
}
|
||||
|
||||
// 初始连接
|
||||
connectWebSocket();
|
||||
let recognition = null;
|
||||
const SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
|
||||
|
||||
function updateStatus(message) {
|
||||
console.log(`[Browser Page Status] ${message}`);
|
||||
statusDiv.textContent = message;
|
||||
}
|
||||
|
||||
function handleMessage(event) {
|
||||
let data;
|
||||
try {
|
||||
data = JSON.parse(event.data);
|
||||
console.log('[Browser Page] Received command:', data);
|
||||
} catch (e) {
|
||||
console.error('[Browser Page] Received non-JSON message:', event.data);
|
||||
return;
|
||||
}
|
||||
|
||||
if (data.type === 'start') {
|
||||
startRecognition();
|
||||
} else if (data.type === 'stop') {
|
||||
stopRecognition();
|
||||
} else if (data.type === 'reset') {
|
||||
// 强制重置语音识别
|
||||
forceResetRecognition();
|
||||
} else {
|
||||
console.warn('[Browser Page] Received unknown command type:', data.type);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
function setupRecognition() {
|
||||
if (!SpeechRecognition) {
|
||||
updateStatus('错误:此浏览器不支持 Web Speech API。');
|
||||
return false;
|
||||
}
|
||||
if (recognition && recognition.recognizing) {
|
||||
console.log('[Browser Page] Recognition already active.');
|
||||
return true;
|
||||
}
|
||||
|
||||
recognition = new SpeechRecognition();
|
||||
recognition.lang = 'zh-CN';
|
||||
recognition.continuous = true;
|
||||
recognition.interimResults = true;
|
||||
// 增加以下设置提高语音识别的可靠性
|
||||
recognition.maxAlternatives = 3; // 返回多个可能的识别结果
|
||||
// 设置较短的语音识别时间,使用户能更快地看到结果
|
||||
// 注意:这个属性不是标准的,可能不是所有浏览器都支持
|
||||
try {
|
||||
// @ts-ignore
|
||||
recognition.audioStart = 0.1; // 尝试设置较低的起始音量阈值
|
||||
} catch (e) {
|
||||
console.log('[Browser Page] audioStart property not supported');
|
||||
}
|
||||
|
||||
recognition.onstart = () => {
|
||||
updateStatus("🎤 正在识别...");
|
||||
console.log('[Browser Page] SpeechRecognition started.');
|
||||
};
|
||||
|
||||
recognition.onresult = (event) => {
|
||||
console.log('[Browser Page] Recognition result event:', event);
|
||||
|
||||
let interim_transcript = '';
|
||||
let final_transcript = '';
|
||||
|
||||
// 输出识别结果的详细信息便于调试
|
||||
for (let i = event.resultIndex; i < event.results.length; ++i) {
|
||||
const confidence = event.results[i][0].confidence;
|
||||
console.log(`[Browser Page] Result ${i}: ${event.results[i][0].transcript} (Confidence: ${confidence.toFixed(2)})`);
|
||||
|
||||
if (event.results[i].isFinal) {
|
||||
final_transcript += event.results[i][0].transcript;
|
||||
} else {
|
||||
interim_transcript += event.results[i][0].transcript;
|
||||
}
|
||||
}
|
||||
|
||||
const resultText = final_transcript || interim_transcript;
|
||||
resultDiv.textContent = resultText;
|
||||
|
||||
// 更新状态显示
|
||||
if (resultText) {
|
||||
updateStatus(`🎤 正在识别... (已捕捉到语音)`);
|
||||
}
|
||||
|
||||
if (ws.readyState === WebSocket.OPEN) {
|
||||
console.log(`[Browser Page] Sending ${final_transcript ? 'final' : 'interim'} result to server:`, resultText);
|
||||
ws.send(JSON.stringify({ type: 'result', data: { text: resultText, isFinal: !!final_transcript } }));
|
||||
}
|
||||
};
|
||||
|
||||
recognition.onerror = (event) => {
|
||||
console.error(`[Browser Page] SpeechRecognition Error - Type: ${event.error}, Message: ${event.message}`);
|
||||
|
||||
// 根据错误类型提供更友好的错误提示
|
||||
let errorMessage = '';
|
||||
switch (event.error) {
|
||||
case 'no-speech':
|
||||
errorMessage = '未检测到语音,请确保麦克风工作正常并尝试说话。';
|
||||
// 尝试重新启动语音识别
|
||||
setTimeout(() => {
|
||||
if (recognition) {
|
||||
try {
|
||||
recognition.start();
|
||||
console.log('[Browser Page] Restarting recognition after no-speech error');
|
||||
} catch (e) {
|
||||
console.error('[Browser Page] Failed to restart recognition:', e);
|
||||
}
|
||||
}
|
||||
}, 1000);
|
||||
break;
|
||||
case 'audio-capture':
|
||||
errorMessage = '无法捕获音频,请确保麦克风已连接并已授权。';
|
||||
break;
|
||||
case 'not-allowed':
|
||||
errorMessage = '浏览器不允许使用麦克风,请检查权限设置。';
|
||||
break;
|
||||
case 'network':
|
||||
errorMessage = '网络错误导致语音识别失败。';
|
||||
break;
|
||||
case 'aborted':
|
||||
errorMessage = '语音识别被用户或系统中止。';
|
||||
break;
|
||||
default:
|
||||
errorMessage = `识别错误: ${event.error}`;
|
||||
}
|
||||
|
||||
updateStatus(`错误: ${errorMessage}`);
|
||||
|
||||
if (ws.readyState === WebSocket.OPEN) {
|
||||
ws.send(JSON.stringify({
|
||||
type: 'error',
|
||||
data: {
|
||||
error: event.error,
|
||||
message: errorMessage || event.message || `Recognition error: ${event.error}`
|
||||
}
|
||||
}));
|
||||
}
|
||||
};
|
||||
|
||||
recognition.onend = () => {
|
||||
console.log('[Browser Page] SpeechRecognition ended.');
|
||||
|
||||
// 检查是否是由于错误或用户手动停止导致的结束
|
||||
const isErrorOrStopped = statusDiv.textContent.includes('错误') || statusDiv.textContent.includes('停止');
|
||||
|
||||
if (!isErrorOrStopped) {
|
||||
// 如果不是由于错误或手动停止,则自动重新启动语音识别
|
||||
updateStatus("识别暂停,正在重新启动...");
|
||||
|
||||
// 保存当前的recognition对象
|
||||
const currentRecognition = recognition;
|
||||
|
||||
// 尝试重新启动语音识别
|
||||
setTimeout(() => {
|
||||
try {
|
||||
if (currentRecognition && currentRecognition === recognition) {
|
||||
currentRecognition.start();
|
||||
console.log('[Browser Page] Automatically restarting recognition');
|
||||
} else {
|
||||
// 如果recognition对象已经变化,重新创建一个
|
||||
setupRecognition();
|
||||
if (recognition) {
|
||||
recognition.start();
|
||||
console.log('[Browser Page] Created new recognition instance and started');
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('[Browser Page] Failed to restart recognition:', e);
|
||||
updateStatus("识别已停止。等待指令...");
|
||||
}
|
||||
}, 300);
|
||||
} else {
|
||||
updateStatus("识别已停止。等待指令...");
|
||||
|
||||
if (ws.readyState === WebSocket.OPEN) {
|
||||
ws.send(JSON.stringify({ type: 'status', message: 'stopped' }));
|
||||
}
|
||||
|
||||
// 只有在手动停止或错误时才重置recognition对象
|
||||
recognition = null;
|
||||
}
|
||||
};
|
||||
return true;
|
||||
}
|
||||
|
||||
function startRecognition() {
|
||||
if (!SpeechRecognition) {
|
||||
updateStatus('错误:浏览器不支持 Web Speech API。');
|
||||
return;
|
||||
}
|
||||
|
||||
// 显示正在准备的状态
|
||||
updateStatus('正在准备麦克风...');
|
||||
|
||||
if (recognition) {
|
||||
console.log('[Browser Page] Recognition already exists, stopping first.');
|
||||
stopRecognition();
|
||||
}
|
||||
|
||||
if (!setupRecognition()) return;
|
||||
|
||||
console.log('[Browser Page] Attempting to start recognition...');
|
||||
try {
|
||||
// 设置更长的超时时间,确保有足够的时间获取麦克风权限
|
||||
const micPermissionTimeout = setTimeout(() => {
|
||||
updateStatus('获取麦克风权限超时,请刷新页面重试。');
|
||||
}, 10000); // 10秒超时
|
||||
|
||||
navigator.mediaDevices.getUserMedia({
|
||||
audio: {
|
||||
echoCancellation: true,
|
||||
noiseSuppression: true,
|
||||
autoGainControl: true
|
||||
}
|
||||
})
|
||||
.then(stream => {
|
||||
clearTimeout(micPermissionTimeout);
|
||||
console.log('[Browser Page] Microphone access granted.');
|
||||
|
||||
// 检查麦克风音量级别
|
||||
const audioContext = new AudioContext();
|
||||
const analyser = audioContext.createAnalyser();
|
||||
const microphone = audioContext.createMediaStreamSource(stream);
|
||||
const javascriptNode = audioContext.createScriptProcessor(2048, 1, 1);
|
||||
|
||||
analyser.smoothingTimeConstant = 0.8;
|
||||
analyser.fftSize = 1024;
|
||||
|
||||
microphone.connect(analyser);
|
||||
analyser.connect(javascriptNode);
|
||||
javascriptNode.connect(audioContext.destination);
|
||||
|
||||
javascriptNode.onaudioprocess = function () {
|
||||
const array = new Uint8Array(analyser.frequencyBinCount);
|
||||
analyser.getByteFrequencyData(array);
|
||||
let values = 0;
|
||||
|
||||
const length = array.length;
|
||||
for (let i = 0; i < length; i++) {
|
||||
values += (array[i]);
|
||||
}
|
||||
|
||||
const average = values / length;
|
||||
console.log('[Browser Page] Microphone volume level:', average);
|
||||
|
||||
// 如果音量太低,显示提示
|
||||
if (average < 5) {
|
||||
updateStatus('麦克风音量很低,请说话或检查麦克风设置。');
|
||||
} else {
|
||||
updateStatus('🎤 正在识别...');
|
||||
}
|
||||
|
||||
// 只检查一次就断开连接
|
||||
microphone.disconnect();
|
||||
analyser.disconnect();
|
||||
javascriptNode.disconnect();
|
||||
};
|
||||
|
||||
// 释放测试用的音频流
|
||||
setTimeout(() => {
|
||||
stream.getTracks().forEach(track => track.stop());
|
||||
audioContext.close();
|
||||
}, 1000);
|
||||
|
||||
// 启动语音识别
|
||||
if (recognition) {
|
||||
recognition.start();
|
||||
updateStatus('🎤 正在识别...');
|
||||
} else {
|
||||
updateStatus('错误:Recognition 实例丢失。');
|
||||
console.error('[Browser Page] Recognition instance lost before start.');
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
clearTimeout(micPermissionTimeout);
|
||||
console.error('[Browser Page] Microphone access error:', err);
|
||||
|
||||
let errorMsg = `无法访问麦克风 (${err.name})`;
|
||||
if (err.name === 'NotAllowedError') {
|
||||
errorMsg = '麦克风访问被拒绝。请在浏览器设置中允许麦克风访问权限。';
|
||||
} else if (err.name === 'NotFoundError') {
|
||||
errorMsg = '未找到麦克风设备。请确保麦克风已连接。';
|
||||
}
|
||||
|
||||
updateStatus(`错误: ${errorMsg}`);
|
||||
recognition = null;
|
||||
});
|
||||
} catch (e) {
|
||||
console.error('[Browser Page] Error calling recognition.start():', e);
|
||||
updateStatus(`启动识别时出错: ${e.message}`);
|
||||
recognition = null;
|
||||
}
|
||||
}
|
||||
|
||||
function stopRecognition() {
|
||||
if (recognition) {
|
||||
console.log('[Browser Page] Stopping recognition...');
|
||||
updateStatus("正在停止识别...");
|
||||
try {
|
||||
recognition.stop();
|
||||
} catch (e) {
|
||||
console.error('[Browser Page] Error calling recognition.stop():', e);
|
||||
recognition = null;
|
||||
updateStatus("停止时出错,已强制重置。");
|
||||
}
|
||||
} else {
|
||||
console.log('[Browser Page] Recognition not active, nothing to stop.');
|
||||
updateStatus("识别未运行。");
|
||||
}
|
||||
}
|
||||
|
||||
function forceResetRecognition() {
|
||||
console.log('[Browser Page] Force resetting recognition...');
|
||||
updateStatus("强制重置语音识别...");
|
||||
|
||||
// 先尝试停止当前的识别
|
||||
if (recognition) {
|
||||
try {
|
||||
recognition.stop();
|
||||
} catch (e) {
|
||||
console.error('[Browser Page] Error stopping recognition during reset:', e);
|
||||
}
|
||||
}
|
||||
|
||||
// 强制设置为null,丢弃所有后续结果
|
||||
recognition = null;
|
||||
|
||||
// 通知服务器已重置
|
||||
if (ws.readyState === WebSocket.OPEN) {
|
||||
ws.send(JSON.stringify({ type: 'status', message: 'reset_complete' }));
|
||||
}
|
||||
|
||||
updateStatus("语音识别已重置,等待新指令。");
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
854
resources/asr-server/package-lock.json
generated
Normal file
854
resources/asr-server/package-lock.json
generated
Normal file
@ -0,0 +1,854 @@
|
||||
{
|
||||
"name": "cherry-asr-server",
|
||||
"version": "1.0.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "cherry-asr-server",
|
||||
"version": "1.0.0",
|
||||
"dependencies": {
|
||||
"express": "^4.18.2",
|
||||
"ws": "^8.13.0"
|
||||
}
|
||||
},
|
||||
"node_modules/accepts": {
|
||||
"version": "1.3.8",
|
||||
"resolved": "https://registry.npmmirror.com/accepts/-/accepts-1.3.8.tgz",
|
||||
"integrity": "sha512-PYAthTa2m2VKxuvSD3DPC/Gy+U+sOA1LAuT8mkmRuvw+NACSaeXEQ+NHcVF7rONl6qcaxV3Uuemwawk+7+SJLw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"mime-types": "~2.1.34",
|
||||
"negotiator": "0.6.3"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/array-flatten": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmmirror.com/array-flatten/-/array-flatten-1.1.1.tgz",
|
||||
"integrity": "sha512-PCVAQswWemu6UdxsDFFX/+gVeYqKAod3D3UVm91jHwynguOwAvYPhx8nNlM++NqRcK6CxxpUafjmhIdKiHibqg==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/body-parser": {
|
||||
"version": "1.20.3",
|
||||
"resolved": "https://registry.npmmirror.com/body-parser/-/body-parser-1.20.3.tgz",
|
||||
"integrity": "sha512-7rAxByjUMqQ3/bHJy7D6OGXvx/MMc4IqBn/X0fcM1QUcAItpZrBEYhWGem+tzXH90c+G01ypMcYJBO9Y30203g==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"bytes": "3.1.2",
|
||||
"content-type": "~1.0.5",
|
||||
"debug": "2.6.9",
|
||||
"depd": "2.0.0",
|
||||
"destroy": "1.2.0",
|
||||
"http-errors": "2.0.0",
|
||||
"iconv-lite": "0.4.24",
|
||||
"on-finished": "2.4.1",
|
||||
"qs": "6.13.0",
|
||||
"raw-body": "2.5.2",
|
||||
"type-is": "~1.6.18",
|
||||
"unpipe": "1.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.8",
|
||||
"npm": "1.2.8000 || >= 1.4.16"
|
||||
}
|
||||
},
|
||||
"node_modules/bytes": {
|
||||
"version": "3.1.2",
|
||||
"resolved": "https://registry.npmmirror.com/bytes/-/bytes-3.1.2.tgz",
|
||||
"integrity": "sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/call-bind-apply-helpers": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmmirror.com/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.2.tgz",
|
||||
"integrity": "sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"es-errors": "^1.3.0",
|
||||
"function-bind": "^1.1.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/call-bound": {
|
||||
"version": "1.0.4",
|
||||
"resolved": "https://registry.npmmirror.com/call-bound/-/call-bound-1.0.4.tgz",
|
||||
"integrity": "sha512-+ys997U96po4Kx/ABpBCqhA9EuxJaQWDQg7295H4hBphv3IZg0boBKuwYpt4YXp6MZ5AmZQnU/tyMTlRpaSejg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"call-bind-apply-helpers": "^1.0.2",
|
||||
"get-intrinsic": "^1.3.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/content-disposition": {
|
||||
"version": "0.5.4",
|
||||
"resolved": "https://registry.npmmirror.com/content-disposition/-/content-disposition-0.5.4.tgz",
|
||||
"integrity": "sha512-FveZTNuGw04cxlAiWbzi6zTAL/lhehaWbTtgluJh4/E95DqMwTmha3KZN1aAWA8cFIhHzMZUvLevkw5Rqk+tSQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"safe-buffer": "5.2.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/content-type": {
|
||||
"version": "1.0.5",
|
||||
"resolved": "https://registry.npmmirror.com/content-type/-/content-type-1.0.5.tgz",
|
||||
"integrity": "sha512-nTjqfcBFEipKdXCv4YDQWCfmcLZKm81ldF0pAopTvyrFGVbcR6P/VAAd5G7N+0tTr8QqiU0tFadD6FK4NtJwOA==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/cookie": {
|
||||
"version": "0.7.1",
|
||||
"resolved": "https://registry.npmmirror.com/cookie/-/cookie-0.7.1.tgz",
|
||||
"integrity": "sha512-6DnInpx7SJ2AK3+CTUE/ZM0vWTUboZCegxhC2xiIydHR9jNuTAASBrfEpHhiGOZw/nX51bHt6YQl8jsGo4y/0w==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/cookie-signature": {
|
||||
"version": "1.0.6",
|
||||
"resolved": "https://registry.npmmirror.com/cookie-signature/-/cookie-signature-1.0.6.tgz",
|
||||
"integrity": "sha512-QADzlaHc8icV8I7vbaJXJwod9HWYp8uCqf1xa4OfNu1T7JVxQIrUgOWtHdNDtPiywmFbiS12VjotIXLrKM3orQ==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/debug": {
|
||||
"version": "2.6.9",
|
||||
"resolved": "https://registry.npmmirror.com/debug/-/debug-2.6.9.tgz",
|
||||
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"ms": "2.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/depd": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmmirror.com/depd/-/depd-2.0.0.tgz",
|
||||
"integrity": "sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/destroy": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmmirror.com/destroy/-/destroy-1.2.0.tgz",
|
||||
"integrity": "sha512-2sJGJTaXIIaR1w4iJSNoN0hnMY7Gpc/n8D4qSCJw8QqFWXf7cuAgnEHxBpweaVcPevC2l3KpjYCx3NypQQgaJg==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.8",
|
||||
"npm": "1.2.8000 || >= 1.4.16"
|
||||
}
|
||||
},
|
||||
"node_modules/dunder-proto": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmmirror.com/dunder-proto/-/dunder-proto-1.0.1.tgz",
|
||||
"integrity": "sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"call-bind-apply-helpers": "^1.0.1",
|
||||
"es-errors": "^1.3.0",
|
||||
"gopd": "^1.2.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/ee-first": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmmirror.com/ee-first/-/ee-first-1.1.1.tgz",
|
||||
"integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/encodeurl": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmmirror.com/encodeurl/-/encodeurl-2.0.0.tgz",
|
||||
"integrity": "sha512-Q0n9HRi4m6JuGIV1eFlmvJB7ZEVxu93IrMyiMsGC0lrMJMWzRgx6WGquyfQgZVb31vhGgXnfmPNNXmxnOkRBrg==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/es-define-property": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmmirror.com/es-define-property/-/es-define-property-1.0.1.tgz",
|
||||
"integrity": "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/es-errors": {
|
||||
"version": "1.3.0",
|
||||
"resolved": "https://registry.npmmirror.com/es-errors/-/es-errors-1.3.0.tgz",
|
||||
"integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/es-object-atoms": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmmirror.com/es-object-atoms/-/es-object-atoms-1.1.1.tgz",
|
||||
"integrity": "sha512-FGgH2h8zKNim9ljj7dankFPcICIK9Cp5bm+c2gQSYePhpaG5+esrLODihIorn+Pe6FGJzWhXQotPv73jTaldXA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"es-errors": "^1.3.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/escape-html": {
|
||||
"version": "1.0.3",
|
||||
"resolved": "https://registry.npmmirror.com/escape-html/-/escape-html-1.0.3.tgz",
|
||||
"integrity": "sha512-NiSupZ4OeuGwr68lGIeym/ksIZMJodUGOSCZ/FSnTxcrekbvqrgdUxlJOMpijaKZVjAJrWrGs/6Jy8OMuyj9ow==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/etag": {
|
||||
"version": "1.8.1",
|
||||
"resolved": "https://registry.npmmirror.com/etag/-/etag-1.8.1.tgz",
|
||||
"integrity": "sha512-aIL5Fx7mawVa300al2BnEE4iNvo1qETxLrPI/o05L7z6go7fCw1J6EQmbK4FmJ2AS7kgVF/KEZWufBfdClMcPg==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/express": {
|
||||
"version": "4.21.2",
|
||||
"resolved": "https://registry.npmmirror.com/express/-/express-4.21.2.tgz",
|
||||
"integrity": "sha512-28HqgMZAmih1Czt9ny7qr6ek2qddF4FclbMzwhCREB6OFfH+rXAnuNCwo1/wFvrtbgsQDb4kSbX9de9lFbrXnA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"accepts": "~1.3.8",
|
||||
"array-flatten": "1.1.1",
|
||||
"body-parser": "1.20.3",
|
||||
"content-disposition": "0.5.4",
|
||||
"content-type": "~1.0.4",
|
||||
"cookie": "0.7.1",
|
||||
"cookie-signature": "1.0.6",
|
||||
"debug": "2.6.9",
|
||||
"depd": "2.0.0",
|
||||
"encodeurl": "~2.0.0",
|
||||
"escape-html": "~1.0.3",
|
||||
"etag": "~1.8.1",
|
||||
"finalhandler": "1.3.1",
|
||||
"fresh": "0.5.2",
|
||||
"http-errors": "2.0.0",
|
||||
"merge-descriptors": "1.0.3",
|
||||
"methods": "~1.1.2",
|
||||
"on-finished": "2.4.1",
|
||||
"parseurl": "~1.3.3",
|
||||
"path-to-regexp": "0.1.12",
|
||||
"proxy-addr": "~2.0.7",
|
||||
"qs": "6.13.0",
|
||||
"range-parser": "~1.2.1",
|
||||
"safe-buffer": "5.2.1",
|
||||
"send": "0.19.0",
|
||||
"serve-static": "1.16.2",
|
||||
"setprototypeof": "1.2.0",
|
||||
"statuses": "2.0.1",
|
||||
"type-is": "~1.6.18",
|
||||
"utils-merge": "1.0.1",
|
||||
"vary": "~1.1.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.10.0"
|
||||
},
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/express"
|
||||
}
|
||||
},
|
||||
"node_modules/finalhandler": {
|
||||
"version": "1.3.1",
|
||||
"resolved": "https://registry.npmmirror.com/finalhandler/-/finalhandler-1.3.1.tgz",
|
||||
"integrity": "sha512-6BN9trH7bp3qvnrRyzsBz+g3lZxTNZTbVO2EV1CS0WIcDbawYVdYvGflME/9QP0h0pYlCDBCTjYa9nZzMDpyxQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"debug": "2.6.9",
|
||||
"encodeurl": "~2.0.0",
|
||||
"escape-html": "~1.0.3",
|
||||
"on-finished": "2.4.1",
|
||||
"parseurl": "~1.3.3",
|
||||
"statuses": "2.0.1",
|
||||
"unpipe": "~1.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/forwarded": {
|
||||
"version": "0.2.0",
|
||||
"resolved": "https://registry.npmmirror.com/forwarded/-/forwarded-0.2.0.tgz",
|
||||
"integrity": "sha512-buRG0fpBtRHSTCOASe6hD258tEubFoRLb4ZNA6NxMVHNw2gOcwHo9wyablzMzOA5z9xA9L1KNjk/Nt6MT9aYow==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/fresh": {
|
||||
"version": "0.5.2",
|
||||
"resolved": "https://registry.npmmirror.com/fresh/-/fresh-0.5.2.tgz",
|
||||
"integrity": "sha512-zJ2mQYM18rEFOudeV4GShTGIQ7RbzA7ozbU9I/XBpm7kqgMywgmylMwXHxZJmkVoYkna9d2pVXVXPdYTP9ej8Q==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/function-bind": {
|
||||
"version": "1.1.2",
|
||||
"resolved": "https://registry.npmmirror.com/function-bind/-/function-bind-1.1.2.tgz",
|
||||
"integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==",
|
||||
"license": "MIT",
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/get-intrinsic": {
|
||||
"version": "1.3.0",
|
||||
"resolved": "https://registry.npmmirror.com/get-intrinsic/-/get-intrinsic-1.3.0.tgz",
|
||||
"integrity": "sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"call-bind-apply-helpers": "^1.0.2",
|
||||
"es-define-property": "^1.0.1",
|
||||
"es-errors": "^1.3.0",
|
||||
"es-object-atoms": "^1.1.1",
|
||||
"function-bind": "^1.1.2",
|
||||
"get-proto": "^1.0.1",
|
||||
"gopd": "^1.2.0",
|
||||
"has-symbols": "^1.1.0",
|
||||
"hasown": "^2.0.2",
|
||||
"math-intrinsics": "^1.1.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/get-proto": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmmirror.com/get-proto/-/get-proto-1.0.1.tgz",
|
||||
"integrity": "sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"dunder-proto": "^1.0.1",
|
||||
"es-object-atoms": "^1.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/gopd": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmmirror.com/gopd/-/gopd-1.2.0.tgz",
|
||||
"integrity": "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/has-symbols": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmmirror.com/has-symbols/-/has-symbols-1.1.0.tgz",
|
||||
"integrity": "sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/hasown": {
|
||||
"version": "2.0.2",
|
||||
"resolved": "https://registry.npmmirror.com/hasown/-/hasown-2.0.2.tgz",
|
||||
"integrity": "sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"function-bind": "^1.1.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/http-errors": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmmirror.com/http-errors/-/http-errors-2.0.0.tgz",
|
||||
"integrity": "sha512-FtwrG/euBzaEjYeRqOgly7G0qviiXoJWnvEH2Z1plBdXgbyjv34pHTSb9zoeHMyDy33+DWy5Wt9Wo+TURtOYSQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"depd": "2.0.0",
|
||||
"inherits": "2.0.4",
|
||||
"setprototypeof": "1.2.0",
|
||||
"statuses": "2.0.1",
|
||||
"toidentifier": "1.0.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/iconv-lite": {
|
||||
"version": "0.4.24",
|
||||
"resolved": "https://registry.npmmirror.com/iconv-lite/-/iconv-lite-0.4.24.tgz",
|
||||
"integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"safer-buffer": ">= 2.1.2 < 3"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.10.0"
|
||||
}
|
||||
},
|
||||
"node_modules/inherits": {
|
||||
"version": "2.0.4",
|
||||
"resolved": "https://registry.npmmirror.com/inherits/-/inherits-2.0.4.tgz",
|
||||
"integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==",
|
||||
"license": "ISC"
|
||||
},
|
||||
"node_modules/ipaddr.js": {
|
||||
"version": "1.9.1",
|
||||
"resolved": "https://registry.npmmirror.com/ipaddr.js/-/ipaddr.js-1.9.1.tgz",
|
||||
"integrity": "sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.10"
|
||||
}
|
||||
},
|
||||
"node_modules/math-intrinsics": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmmirror.com/math-intrinsics/-/math-intrinsics-1.1.0.tgz",
|
||||
"integrity": "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/media-typer": {
|
||||
"version": "0.3.0",
|
||||
"resolved": "https://registry.npmmirror.com/media-typer/-/media-typer-0.3.0.tgz",
|
||||
"integrity": "sha512-dq+qelQ9akHpcOl/gUVRTxVIOkAJ1wR3QAvb4RsVjS8oVoFjDGTc679wJYmUmknUF5HwMLOgb5O+a3KxfWapPQ==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/merge-descriptors": {
|
||||
"version": "1.0.3",
|
||||
"resolved": "https://registry.npmmirror.com/merge-descriptors/-/merge-descriptors-1.0.3.tgz",
|
||||
"integrity": "sha512-gaNvAS7TZ897/rVaZ0nMtAyxNyi/pdbjbAwUpFQpN70GqnVfOiXpeUUMKRBmzXaSQ8DdTX4/0ms62r2K+hE6mQ==",
|
||||
"license": "MIT",
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/sindresorhus"
|
||||
}
|
||||
},
|
||||
"node_modules/methods": {
|
||||
"version": "1.1.2",
|
||||
"resolved": "https://registry.npmmirror.com/methods/-/methods-1.1.2.tgz",
|
||||
"integrity": "sha512-iclAHeNqNm68zFtnZ0e+1L2yUIdvzNoauKU4WBA3VvH/vPFieF7qfRlwUZU+DA9P9bPXIS90ulxoUoCH23sV2w==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/mime": {
|
||||
"version": "1.6.0",
|
||||
"resolved": "https://registry.npmmirror.com/mime/-/mime-1.6.0.tgz",
|
||||
"integrity": "sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg==",
|
||||
"license": "MIT",
|
||||
"bin": {
|
||||
"mime": "cli.js"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=4"
|
||||
}
|
||||
},
|
||||
"node_modules/mime-db": {
|
||||
"version": "1.52.0",
|
||||
"resolved": "https://registry.npmmirror.com/mime-db/-/mime-db-1.52.0.tgz",
|
||||
"integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/mime-types": {
|
||||
"version": "2.1.35",
|
||||
"resolved": "https://registry.npmmirror.com/mime-types/-/mime-types-2.1.35.tgz",
|
||||
"integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"mime-db": "1.52.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/ms": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmmirror.com/ms/-/ms-2.0.0.tgz",
|
||||
"integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/negotiator": {
|
||||
"version": "0.6.3",
|
||||
"resolved": "https://registry.npmmirror.com/negotiator/-/negotiator-0.6.3.tgz",
|
||||
"integrity": "sha512-+EUsqGPLsM+j/zdChZjsnX51g4XrHFOIXwfnCVPGlQk/k5giakcKsuxCObBRu6DSm9opw/O6slWbJdghQM4bBg==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/object-inspect": {
|
||||
"version": "1.13.4",
|
||||
"resolved": "https://registry.npmmirror.com/object-inspect/-/object-inspect-1.13.4.tgz",
|
||||
"integrity": "sha512-W67iLl4J2EXEGTbfeHCffrjDfitvLANg0UlX3wFUUSTx92KXRFegMHUVgSqE+wvhAbi4WqjGg9czysTV2Epbew==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/on-finished": {
|
||||
"version": "2.4.1",
|
||||
"resolved": "https://registry.npmmirror.com/on-finished/-/on-finished-2.4.1.tgz",
|
||||
"integrity": "sha512-oVlzkg3ENAhCk2zdv7IJwd/QUD4z2RxRwpkcGY8psCVcCYZNq4wYnVWALHM+brtuJjePWiYF/ClmuDr8Ch5+kg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"ee-first": "1.1.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/parseurl": {
|
||||
"version": "1.3.3",
|
||||
"resolved": "https://registry.npmmirror.com/parseurl/-/parseurl-1.3.3.tgz",
|
||||
"integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/path-to-regexp": {
|
||||
"version": "0.1.12",
|
||||
"resolved": "https://registry.npmmirror.com/path-to-regexp/-/path-to-regexp-0.1.12.tgz",
|
||||
"integrity": "sha512-RA1GjUVMnvYFxuqovrEqZoxxW5NUZqbwKtYz/Tt7nXerk0LbLblQmrsgdeOxV5SFHf0UDggjS/bSeOZwt1pmEQ==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/proxy-addr": {
|
||||
"version": "2.0.7",
|
||||
"resolved": "https://registry.npmmirror.com/proxy-addr/-/proxy-addr-2.0.7.tgz",
|
||||
"integrity": "sha512-llQsMLSUDUPT44jdrU/O37qlnifitDP+ZwrmmZcoSKyLKvtZxpyV0n2/bD/N4tBAAZ/gJEdZU7KMraoK1+XYAg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"forwarded": "0.2.0",
|
||||
"ipaddr.js": "1.9.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.10"
|
||||
}
|
||||
},
|
||||
"node_modules/qs": {
|
||||
"version": "6.13.0",
|
||||
"resolved": "https://registry.npmmirror.com/qs/-/qs-6.13.0.tgz",
|
||||
"integrity": "sha512-+38qI9SOr8tfZ4QmJNplMUxqjbe7LKvvZgWdExBOmd+egZTtjLB67Gu0HRX3u/XOq7UU2Nx6nsjvS16Z9uwfpg==",
|
||||
"license": "BSD-3-Clause",
|
||||
"dependencies": {
|
||||
"side-channel": "^1.0.6"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.6"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/range-parser": {
|
||||
"version": "1.2.1",
|
||||
"resolved": "https://registry.npmmirror.com/range-parser/-/range-parser-1.2.1.tgz",
|
||||
"integrity": "sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/raw-body": {
|
||||
"version": "2.5.2",
|
||||
"resolved": "https://registry.npmmirror.com/raw-body/-/raw-body-2.5.2.tgz",
|
||||
"integrity": "sha512-8zGqypfENjCIqGhgXToC8aB2r7YrBX+AQAfIPs/Mlk+BtPTztOvTS01NRW/3Eh60J+a48lt8qsCzirQ6loCVfA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"bytes": "3.1.2",
|
||||
"http-errors": "2.0.0",
|
||||
"iconv-lite": "0.4.24",
|
||||
"unpipe": "1.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/safe-buffer": {
|
||||
"version": "5.2.1",
|
||||
"resolved": "https://registry.npmmirror.com/safe-buffer/-/safe-buffer-5.2.1.tgz",
|
||||
"integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==",
|
||||
"funding": [
|
||||
{
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/feross"
|
||||
},
|
||||
{
|
||||
"type": "patreon",
|
||||
"url": "https://www.patreon.com/feross"
|
||||
},
|
||||
{
|
||||
"type": "consulting",
|
||||
"url": "https://feross.org/support"
|
||||
}
|
||||
],
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/safer-buffer": {
|
||||
"version": "2.1.2",
|
||||
"resolved": "https://registry.npmmirror.com/safer-buffer/-/safer-buffer-2.1.2.tgz",
|
||||
"integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/send": {
|
||||
"version": "0.19.0",
|
||||
"resolved": "https://registry.npmmirror.com/send/-/send-0.19.0.tgz",
|
||||
"integrity": "sha512-dW41u5VfLXu8SJh5bwRmyYUbAoSB3c9uQh6L8h/KtsFREPWpbX1lrljJo186Jc4nmci/sGUZ9a0a0J2zgfq2hw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"debug": "2.6.9",
|
||||
"depd": "2.0.0",
|
||||
"destroy": "1.2.0",
|
||||
"encodeurl": "~1.0.2",
|
||||
"escape-html": "~1.0.3",
|
||||
"etag": "~1.8.1",
|
||||
"fresh": "0.5.2",
|
||||
"http-errors": "2.0.0",
|
||||
"mime": "1.6.0",
|
||||
"ms": "2.1.3",
|
||||
"on-finished": "2.4.1",
|
||||
"range-parser": "~1.2.1",
|
||||
"statuses": "2.0.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.8.0"
|
||||
}
|
||||
},
|
||||
"node_modules/send/node_modules/encodeurl": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmmirror.com/encodeurl/-/encodeurl-1.0.2.tgz",
|
||||
"integrity": "sha512-TPJXq8JqFaVYm2CWmPvnP2Iyo4ZSM7/QKcSmuMLDObfpH5fi7RUGmd/rTDf+rut/saiDiQEeVTNgAmJEdAOx0w==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/send/node_modules/ms": {
|
||||
"version": "2.1.3",
|
||||
"resolved": "https://registry.npmmirror.com/ms/-/ms-2.1.3.tgz",
|
||||
"integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/serve-static": {
|
||||
"version": "1.16.2",
|
||||
"resolved": "https://registry.npmmirror.com/serve-static/-/serve-static-1.16.2.tgz",
|
||||
"integrity": "sha512-VqpjJZKadQB/PEbEwvFdO43Ax5dFBZ2UECszz8bQ7pi7wt//PWe1P6MN7eCnjsatYtBT6EuiClbjSWP2WrIoTw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"encodeurl": "~2.0.0",
|
||||
"escape-html": "~1.0.3",
|
||||
"parseurl": "~1.3.3",
|
||||
"send": "0.19.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.8.0"
|
||||
}
|
||||
},
|
||||
"node_modules/setprototypeof": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmmirror.com/setprototypeof/-/setprototypeof-1.2.0.tgz",
|
||||
"integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==",
|
||||
"license": "ISC"
|
||||
},
|
||||
"node_modules/side-channel": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmmirror.com/side-channel/-/side-channel-1.1.0.tgz",
|
||||
"integrity": "sha512-ZX99e6tRweoUXqR+VBrslhda51Nh5MTQwou5tnUDgbtyM0dBgmhEDtWGP/xbKn6hqfPRHujUNwz5fy/wbbhnpw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"es-errors": "^1.3.0",
|
||||
"object-inspect": "^1.13.3",
|
||||
"side-channel-list": "^1.0.0",
|
||||
"side-channel-map": "^1.0.1",
|
||||
"side-channel-weakmap": "^1.0.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/side-channel-list": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmmirror.com/side-channel-list/-/side-channel-list-1.0.0.tgz",
|
||||
"integrity": "sha512-FCLHtRD/gnpCiCHEiJLOwdmFP+wzCmDEkc9y7NsYxeF4u7Btsn1ZuwgwJGxImImHicJArLP4R0yX4c2KCrMrTA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"es-errors": "^1.3.0",
|
||||
"object-inspect": "^1.13.3"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/side-channel-map": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmmirror.com/side-channel-map/-/side-channel-map-1.0.1.tgz",
|
||||
"integrity": "sha512-VCjCNfgMsby3tTdo02nbjtM/ewra6jPHmpThenkTYh8pG9ucZ/1P8So4u4FGBek/BjpOVsDCMoLA/iuBKIFXRA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"call-bound": "^1.0.2",
|
||||
"es-errors": "^1.3.0",
|
||||
"get-intrinsic": "^1.2.5",
|
||||
"object-inspect": "^1.13.3"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/side-channel-weakmap": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmmirror.com/side-channel-weakmap/-/side-channel-weakmap-1.0.2.tgz",
|
||||
"integrity": "sha512-WPS/HvHQTYnHisLo9McqBHOJk2FkHO/tlpvldyrnem4aeQp4hai3gythswg6p01oSoTl58rcpiFAjF2br2Ak2A==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"call-bound": "^1.0.2",
|
||||
"es-errors": "^1.3.0",
|
||||
"get-intrinsic": "^1.2.5",
|
||||
"object-inspect": "^1.13.3",
|
||||
"side-channel-map": "^1.0.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/statuses": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmmirror.com/statuses/-/statuses-2.0.1.tgz",
|
||||
"integrity": "sha512-RwNA9Z/7PrK06rYLIzFMlaF+l73iwpzsqRIFgbMLbTcLD6cOao82TaWefPXQvB2fOC4AjuYSEndS7N/mTCbkdQ==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/toidentifier": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmmirror.com/toidentifier/-/toidentifier-1.0.1.tgz",
|
||||
"integrity": "sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/type-is": {
|
||||
"version": "1.6.18",
|
||||
"resolved": "https://registry.npmmirror.com/type-is/-/type-is-1.6.18.tgz",
|
||||
"integrity": "sha512-TkRKr9sUTxEH8MdfuCSP7VizJyzRNMjj2J2do2Jr3Kym598JVdEksuzPQCnlFPW4ky9Q+iA+ma9BGm06XQBy8g==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"media-typer": "0.3.0",
|
||||
"mime-types": "~2.1.24"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/unpipe": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmmirror.com/unpipe/-/unpipe-1.0.0.tgz",
|
||||
"integrity": "sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/utils-merge": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmmirror.com/utils-merge/-/utils-merge-1.0.1.tgz",
|
||||
"integrity": "sha512-pMZTvIkT1d+TFGvDOqodOclx0QWkkgi6Tdoa8gC8ffGAAqz9pzPTZWAybbsHHoED/ztMtkv/VoYTYyShUn81hA==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.4.0"
|
||||
}
|
||||
},
|
||||
"node_modules/vary": {
|
||||
"version": "1.1.2",
|
||||
"resolved": "https://registry.npmmirror.com/vary/-/vary-1.1.2.tgz",
|
||||
"integrity": "sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/ws": {
|
||||
"version": "8.18.1",
|
||||
"resolved": "https://registry.npmmirror.com/ws/-/ws-8.18.1.tgz",
|
||||
"integrity": "sha512-RKW2aJZMXeMxVpnZ6bck+RswznaxmzdULiBr6KY7XkTnW8uvt0iT9H5DkHUChXrc+uurzwa0rVI16n/Xzjdz1w==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=10.0.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"bufferutil": "^4.0.1",
|
||||
"utf-8-validate": ">=5.0.2"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"bufferutil": {
|
||||
"optional": true
|
||||
},
|
||||
"utf-8-validate": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
10
resources/asr-server/package.json
Normal file
10
resources/asr-server/package.json
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"name": "cherry-asr-server",
|
||||
"version": "1.0.0",
|
||||
"description": "Cherry Studio ASR Server",
|
||||
"main": "server.js",
|
||||
"dependencies": {
|
||||
"express": "^4.18.2",
|
||||
"ws": "^8.13.0"
|
||||
}
|
||||
}
|
||||
269
resources/asr-server/server.js
Normal file
269
resources/asr-server/server.js
Normal file
@ -0,0 +1,269 @@
|
||||
// 检查依赖项
|
||||
try {
|
||||
console.log('ASR Server starting...')
|
||||
console.log('Node.js version:', process.version)
|
||||
console.log('Current directory:', __dirname)
|
||||
console.log('Current working directory:', process.cwd())
|
||||
console.log('Command line arguments:', process.argv)
|
||||
|
||||
// 检查必要的依赖项
|
||||
const checkDependency = (name) => {
|
||||
try {
|
||||
require(name) // Removed unused variable 'module'
|
||||
console.log(`Successfully loaded dependency: ${name}`)
|
||||
return true
|
||||
} catch (error) {
|
||||
console.error(`Failed to load dependency: ${name}`, error.message)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// 检查所有必要的依赖项
|
||||
const dependencies = ['http', 'ws', 'express', 'path', 'fs']
|
||||
const missingDeps = dependencies.filter((dep) => !checkDependency(dep))
|
||||
|
||||
if (missingDeps.length > 0) {
|
||||
console.error(`Missing dependencies: ${missingDeps.join(', ')}. Server cannot start.`)
|
||||
process.exit(1)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error during dependency check:', error)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
// 加载依赖项
|
||||
const http = require('http')
|
||||
const WebSocket = require('ws')
|
||||
const express = require('express')
|
||||
const path = require('path') // Need path module
|
||||
// const fs = require('fs') // Commented out unused import 'fs'
|
||||
|
||||
const app = express()
|
||||
const port = 34515 // Define the port
|
||||
|
||||
// 获取index.html文件的路径
|
||||
function getIndexHtmlPath() {
|
||||
const fs = require('fs')
|
||||
console.log('Current directory:', __dirname)
|
||||
console.log('Current working directory:', process.cwd())
|
||||
|
||||
// 尝试多个可能的路径
|
||||
const possiblePaths = [
|
||||
// 开发环境路径
|
||||
path.join(__dirname, 'index.html'),
|
||||
// 当前目录
|
||||
path.join(process.cwd(), 'index.html'),
|
||||
// 相对于可执行文件的路径
|
||||
path.join(path.dirname(process.execPath), 'index.html'),
|
||||
// 相对于可执行文件的上级目录的路径
|
||||
path.join(path.dirname(path.dirname(process.execPath)), 'index.html'),
|
||||
// 相对于可执行文件的resources目录的路径
|
||||
path.join(path.dirname(process.execPath), 'resources', 'index.html'),
|
||||
// 相对于可执行文件的resources/asr-server目录的路径
|
||||
path.join(path.dirname(process.execPath), 'resources', 'asr-server', 'index.html'),
|
||||
// 相对于可执行文件的asr-server目录的路径
|
||||
path.join(path.dirname(process.execPath), 'asr-server', 'index.html'),
|
||||
// 如果是pkg打包环境
|
||||
process.pkg ? path.join(path.dirname(process.execPath), 'index.html') : null
|
||||
].filter(Boolean) // 过滤掉null值
|
||||
|
||||
console.log('Possible index.html paths:', possiblePaths)
|
||||
|
||||
// 检查每个路径,返回第一个存在的文件
|
||||
for (const p of possiblePaths) {
|
||||
try {
|
||||
if (fs.existsSync(p)) {
|
||||
console.log(`Found index.html at: ${p}`)
|
||||
return p
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(`Error checking existence of ${p}:`, e)
|
||||
}
|
||||
}
|
||||
|
||||
// 如果没有找到文件,返回默认路径并记录错误
|
||||
console.error('Could not find index.html in any of the expected locations')
|
||||
return path.join(__dirname, 'index.html') // 返回默认路径,即使它可能不存在
|
||||
}
|
||||
|
||||
// 提供网页给浏览器
|
||||
app.get('/', (req, res) => {
|
||||
try {
|
||||
const indexPath = getIndexHtmlPath()
|
||||
console.log(`Serving index.html from: ${indexPath}`)
|
||||
|
||||
// 检查文件是否存在
|
||||
const fs = require('fs')
|
||||
if (!fs.existsSync(indexPath)) {
|
||||
console.error(`Error: index.html not found at ${indexPath}`)
|
||||
return res.status(404).send(`Error: index.html not found at ${indexPath}. <br>Please check the server logs.`)
|
||||
}
|
||||
|
||||
res.sendFile(indexPath, (err) => {
|
||||
if (err) {
|
||||
console.error('Error sending index.html:', err)
|
||||
res.status(500).send(`Error serving index.html: ${err.message}`)
|
||||
}
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('Error in route handler:', error)
|
||||
res.status(500).send(`Server error: ${error.message}`)
|
||||
}
|
||||
})
|
||||
|
||||
const server = http.createServer(app)
|
||||
const wss = new WebSocket.Server({ server })
|
||||
|
||||
let browserConnection = null
|
||||
let electronConnection = null
|
||||
|
||||
wss.on('connection', (ws) => {
|
||||
console.log('[Server] WebSocket client connected') // Add log
|
||||
|
||||
ws.on('message', (message) => {
|
||||
let data
|
||||
try {
|
||||
// Ensure message is treated as string before parsing
|
||||
data = JSON.parse(message.toString())
|
||||
console.log('[Server] Received message:', data) // Log parsed data
|
||||
} catch (e) {
|
||||
console.error('[Server] Failed to parse message or message is not JSON:', message.toString(), e)
|
||||
return // Ignore non-JSON messages
|
||||
}
|
||||
|
||||
// 识别客户端类型
|
||||
if (data.type === 'identify') {
|
||||
if (data.role === 'browser') {
|
||||
browserConnection = ws
|
||||
console.log('[Server] Browser identified and connected')
|
||||
// Notify Electron that the browser is ready
|
||||
if (electronConnection && electronConnection.readyState === WebSocket.OPEN) {
|
||||
electronConnection.send(JSON.stringify({ type: 'status', message: 'browser_ready' }))
|
||||
console.log('[Server] Sent browser_ready status to Electron')
|
||||
}
|
||||
// Notify Electron if it's already connected
|
||||
if (electronConnection) {
|
||||
electronConnection.send(JSON.stringify({ type: 'status', message: 'Browser connected' }))
|
||||
}
|
||||
ws.on('close', () => {
|
||||
console.log('[Server] Browser disconnected')
|
||||
browserConnection = null
|
||||
// Notify Electron
|
||||
if (electronConnection) {
|
||||
electronConnection.send(JSON.stringify({ type: 'status', message: 'Browser disconnected' }))
|
||||
}
|
||||
})
|
||||
ws.on('error', (error) => {
|
||||
console.error('[Server] Browser WebSocket error:', error)
|
||||
browserConnection = null // Assume disconnected on error
|
||||
if (electronConnection) {
|
||||
electronConnection.send(JSON.stringify({ type: 'status', message: 'Browser connection error' }))
|
||||
}
|
||||
})
|
||||
} else if (data.role === 'electron') {
|
||||
electronConnection = ws
|
||||
console.log('[Server] Electron identified and connected')
|
||||
// If browser is already connected when Electron connects, notify Electron immediately
|
||||
if (browserConnection && browserConnection.readyState === WebSocket.OPEN) {
|
||||
electronConnection.send(JSON.stringify({ type: 'status', message: 'browser_ready' }))
|
||||
console.log('[Server] Sent initial browser_ready status to Electron')
|
||||
}
|
||||
ws.on('close', () => {
|
||||
console.log('[Server] Electron disconnected')
|
||||
electronConnection = null
|
||||
// Maybe send stop to browser if electron disconnects?
|
||||
// if (browserConnection) browserConnection.send(JSON.stringify({ type: 'stop' }));
|
||||
})
|
||||
ws.on('error', (error) => {
|
||||
console.error('[Server] Electron WebSocket error:', error)
|
||||
electronConnection = null // Assume disconnected on error
|
||||
})
|
||||
}
|
||||
}
|
||||
// Electron 控制开始/停止
|
||||
else if (data.type === 'start' && ws === electronConnection) {
|
||||
if (browserConnection && browserConnection.readyState === WebSocket.OPEN) {
|
||||
console.log('[Server] Relaying START command to browser')
|
||||
browserConnection.send(JSON.stringify({ type: 'start' }))
|
||||
} else {
|
||||
console.log('[Server] Cannot relay START: Browser not connected')
|
||||
// Optionally notify Electron back
|
||||
electronConnection.send(JSON.stringify({ type: 'error', message: 'Browser not connected for ASR' }))
|
||||
}
|
||||
} else if (data.type === 'stop' && ws === electronConnection) {
|
||||
if (browserConnection && browserConnection.readyState === WebSocket.OPEN) {
|
||||
console.log('[Server] Relaying STOP command to browser')
|
||||
browserConnection.send(JSON.stringify({ type: 'stop' }))
|
||||
} else {
|
||||
console.log('[Server] Cannot relay STOP: Browser not connected')
|
||||
}
|
||||
} else if (data.type === 'reset' && ws === electronConnection) {
|
||||
if (browserConnection && browserConnection.readyState === WebSocket.OPEN) {
|
||||
console.log('[Server] Relaying RESET command to browser')
|
||||
browserConnection.send(JSON.stringify({ type: 'reset' }))
|
||||
} else {
|
||||
console.log('[Server] Cannot relay RESET: Browser not connected')
|
||||
}
|
||||
}
|
||||
// 浏览器发送识别结果
|
||||
else if (data.type === 'result' && ws === browserConnection) {
|
||||
if (electronConnection && electronConnection.readyState === WebSocket.OPEN) {
|
||||
// console.log('[Server] Relaying RESULT to Electron:', data.data); // Log less frequently if needed
|
||||
electronConnection.send(JSON.stringify({ type: 'result', data: data.data }))
|
||||
} else {
|
||||
// console.log('[Server] Cannot relay RESULT: Electron not connected');
|
||||
}
|
||||
}
|
||||
// 浏览器发送状态更新 (例如 'stopped')
|
||||
else if (data.type === 'status' && ws === browserConnection) {
|
||||
if (electronConnection && electronConnection.readyState === WebSocket.OPEN) {
|
||||
console.log('[Server] Relaying STATUS to Electron:', data.message) // Log status being relayed
|
||||
electronConnection.send(JSON.stringify({ type: 'status', message: data.message }))
|
||||
} else {
|
||||
console.log('[Server] Cannot relay STATUS: Electron not connected')
|
||||
}
|
||||
} else {
|
||||
console.log('[Server] Received unknown message type or from unknown source:', data)
|
||||
}
|
||||
})
|
||||
|
||||
ws.on('error', (error) => {
|
||||
// Generic error handling for connection before identification
|
||||
console.error('[Server] Initial WebSocket connection error:', error)
|
||||
// Attempt to clean up based on which connection it might be (if identified)
|
||||
if (ws === browserConnection) {
|
||||
browserConnection = null
|
||||
if (electronConnection)
|
||||
electronConnection.send(JSON.stringify({ type: 'status', message: 'Browser connection error' }))
|
||||
} else if (ws === electronConnection) {
|
||||
electronConnection = null
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
// 添加进程错误处理
|
||||
process.on('uncaughtException', (error) => {
|
||||
console.error('[Server] Uncaught exception:', error)
|
||||
// 不立即退出,给日志输出的时间
|
||||
setTimeout(() => process.exit(1), 1000)
|
||||
})
|
||||
|
||||
process.on('unhandledRejection', (reason, promise) => {
|
||||
console.error('[Server] Unhandled rejection at:', promise, 'reason:', reason)
|
||||
})
|
||||
|
||||
// 尝试启动服务器
|
||||
try {
|
||||
server.listen(port, () => {
|
||||
console.log(`[Server] Server running at http://localhost:${port}`)
|
||||
})
|
||||
|
||||
// Handle server errors
|
||||
server.on('error', (error) => {
|
||||
console.error(`[Server] Failed to start server:`, error)
|
||||
process.exit(1) // Exit if server fails to start
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('[Server] Critical error starting server:', error)
|
||||
process.exit(1)
|
||||
}
|
||||
114
resources/asr-server/standalone.js
Normal file
114
resources/asr-server/standalone.js
Normal file
@ -0,0 +1,114 @@
|
||||
/**
|
||||
* 独立的ASR服务器
|
||||
* 这个文件是一个简化版的server.js,用于在打包后的应用中运行
|
||||
*/
|
||||
|
||||
// 基本依赖
|
||||
const http = require('http')
|
||||
const express = require('express')
|
||||
const path = require('path')
|
||||
const fs = require('fs')
|
||||
|
||||
// 输出环境信息
|
||||
console.log('ASR Server starting...')
|
||||
console.log('Node.js version:', process.version)
|
||||
console.log('Current directory:', __dirname)
|
||||
console.log('Current working directory:', process.cwd())
|
||||
console.log('Command line arguments:', process.argv)
|
||||
|
||||
// 创建Express应用
|
||||
const app = express()
|
||||
const port = 34515
|
||||
|
||||
// 提供静态文件
|
||||
app.use(express.static(__dirname))
|
||||
|
||||
// 提供网页给浏览器
|
||||
app.get('/', (req, res) => {
|
||||
try {
|
||||
// 尝试多个可能的路径
|
||||
const possiblePaths = [
|
||||
// 当前目录
|
||||
path.join(__dirname, 'index.html'),
|
||||
// 上级目录
|
||||
path.join(__dirname, '..', 'index.html'),
|
||||
// 应用根目录
|
||||
path.join(process.cwd(), 'index.html')
|
||||
]
|
||||
|
||||
console.log('Possible index.html paths:', possiblePaths)
|
||||
|
||||
// 查找第一个存在的文件
|
||||
let indexPath = null
|
||||
for (const p of possiblePaths) {
|
||||
try {
|
||||
if (fs.existsSync(p)) {
|
||||
indexPath = p
|
||||
console.log(`Found index.html at: ${p}`)
|
||||
break
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(`Error checking existence of ${p}:`, e)
|
||||
}
|
||||
}
|
||||
|
||||
if (indexPath) {
|
||||
res.sendFile(indexPath)
|
||||
} else {
|
||||
// 如果找不到文件,返回一个简单的HTML页面
|
||||
console.error('Could not find index.html, serving fallback page')
|
||||
res.send(`
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>ASR Server</title>
|
||||
<style>
|
||||
body { font-family: sans-serif; padding: 2em; }
|
||||
h1 { color: #333; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>ASR Server is running</h1>
|
||||
<p>This is a fallback page because the index.html file could not be found.</p>
|
||||
<p>Server is running at: http://localhost:${port}</p>
|
||||
<p>Current directory: ${__dirname}</p>
|
||||
<p>Working directory: ${process.cwd()}</p>
|
||||
</body>
|
||||
</html>
|
||||
`)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error serving index.html:', error)
|
||||
res.status(500).send(`Server error: ${error.message}`)
|
||||
}
|
||||
})
|
||||
|
||||
// 创建HTTP服务器
|
||||
const server = http.createServer(app)
|
||||
|
||||
// 添加进程错误处理
|
||||
process.on('uncaughtException', (error) => {
|
||||
console.error('[Server] Uncaught exception:', error)
|
||||
// 不立即退出,给日志输出的时间
|
||||
setTimeout(() => process.exit(1), 1000)
|
||||
})
|
||||
|
||||
process.on('unhandledRejection', (reason, promise) => {
|
||||
console.error('[Server] Unhandled rejection at:', promise, 'reason:', reason)
|
||||
})
|
||||
|
||||
// 尝试启动服务器
|
||||
try {
|
||||
server.listen(port, () => {
|
||||
console.log(`[Server] Server running at http://localhost:${port}`)
|
||||
})
|
||||
|
||||
// 处理服务器错误
|
||||
server.on('error', (error) => {
|
||||
console.error(`[Server] Failed to start server:`, error)
|
||||
process.exit(1) // Exit if server fails to start
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('[Server] Critical error starting server:', error)
|
||||
process.exit(1)
|
||||
}
|
||||
5
resources/asr-server/start-server.bat
Normal file
5
resources/asr-server/start-server.bat
Normal file
@ -0,0 +1,5 @@
|
||||
@echo off
|
||||
echo Starting ASR Server...
|
||||
cd /d %~dp0
|
||||
node standalone.js
|
||||
pause
|
||||
@ -37,21 +37,21 @@ class ASRServerService {
|
||||
log.info('App path:', app.getAppPath())
|
||||
// 在开发环境和生产环境中使用不同的路径
|
||||
let serverPath = ''
|
||||
let isExeFile = false
|
||||
const isPackaged = app.isPackaged
|
||||
|
||||
// 首先检查是否有打包后的exe文件
|
||||
const exePath = path.join(app.getAppPath(), 'resources', 'cherry-asr-server.exe')
|
||||
if (fs.existsSync(exePath)) {
|
||||
serverPath = exePath
|
||||
isExeFile = true
|
||||
log.info('检测到打包后的exe文件:', serverPath)
|
||||
} else if (process.env.NODE_ENV === 'development') {
|
||||
// 开发环境
|
||||
serverPath = path.join(app.getAppPath(), 'src', 'renderer', 'src', 'assets', 'asr-server', 'server.js')
|
||||
if (isPackaged) {
|
||||
// 生产环境 (打包后) - 使用 extraResources 复制的路径
|
||||
// 注意: 'app' 是 extraResources 配置中 'to' 字段的一部分
|
||||
serverPath = path.join(process.resourcesPath, 'app', 'asr-server', 'server.js')
|
||||
log.info('生产环境,ASR 服务器路径:', serverPath)
|
||||
} else {
|
||||
// 生产环境
|
||||
serverPath = path.join(app.getAppPath(), 'public', 'asr-server', 'server.js')
|
||||
// 开发环境 - 指向项目根目录的 asr-server
|
||||
serverPath = path.join(app.getAppPath(), 'asr-server', 'server.js')
|
||||
log.info('开发环境,ASR 服务器路径:', serverPath)
|
||||
}
|
||||
|
||||
// 注意:删除了 isExeFile 检查逻辑, 假设总是用 node 启动
|
||||
// Removed unused variable 'isExeFile'
|
||||
log.info('ASR服务器路径:', serverPath)
|
||||
|
||||
// 检查文件是否存在
|
||||
@ -60,19 +60,12 @@ class ASRServerService {
|
||||
}
|
||||
|
||||
// 启动服务器进程
|
||||
if (isExeFile) {
|
||||
// 如果是exe文件,直接启动
|
||||
this.asrServerProcess = spawn(serverPath, [], {
|
||||
stdio: 'pipe',
|
||||
detached: false
|
||||
})
|
||||
} else {
|
||||
// 如果是js文件,使用node启动
|
||||
this.asrServerProcess = spawn('node', [serverPath], {
|
||||
stdio: 'pipe',
|
||||
detached: false
|
||||
})
|
||||
}
|
||||
// 始终使用 node 启动 server.js
|
||||
log.info(`尝试使用 node 启动: ${serverPath}`)
|
||||
this.asrServerProcess = spawn('node', [serverPath], {
|
||||
stdio: 'pipe', // 'pipe' 用于捕获输出, 如果需要调试可以临时改为 'inherit'
|
||||
detached: false // false 通常足够
|
||||
})
|
||||
|
||||
// 处理服务器输出
|
||||
this.asrServerProcess.stdout?.on('data', (data) => {
|
||||
|
||||
@ -4,7 +4,8 @@ import path from 'node:path'
|
||||
import { app } from 'electron'
|
||||
|
||||
export function getResourcePath() {
|
||||
return path.join(app.getAppPath(), 'resources')
|
||||
// 在打包环境中,使用process.resourcesPath,否则使用app.getAppPath()/resources
|
||||
return app.isPackaged ? process.resourcesPath : path.join(app.getAppPath(), 'resources')
|
||||
}
|
||||
|
||||
export function getDataPath() {
|
||||
|
||||
@ -4,7 +4,7 @@ const express = require('express')
|
||||
const path = require('path') // Need path module
|
||||
|
||||
const app = express()
|
||||
const port = 8080 // Define the port
|
||||
const port = 34515 // Define the port
|
||||
|
||||
// 获取index.html文件的路径
|
||||
function getIndexHtmlPath() {
|
||||
|
||||
@ -1,4 +1,6 @@
|
||||
import { RootState } from '@renderer/store'
|
||||
import React, { useEffect, useState } from 'react'
|
||||
import { useSelector } from 'react-redux'
|
||||
import styled from 'styled-components'
|
||||
|
||||
interface TTSProgressBarProps {
|
||||
@ -13,6 +15,9 @@ interface TTSProgressState {
|
||||
}
|
||||
|
||||
const TTSProgressBar: React.FC<TTSProgressBarProps> = ({ messageId }) => {
|
||||
// 获取是否显示TTS进度条的设置
|
||||
const showTTSProgressBar = useSelector((state: RootState) => state.settings.showTTSProgressBar)
|
||||
|
||||
const [progressState, setProgressState] = useState<TTSProgressState>({
|
||||
isPlaying: false,
|
||||
progress: 0,
|
||||
@ -20,22 +25,40 @@ const TTSProgressBar: React.FC<TTSProgressBarProps> = ({ messageId }) => {
|
||||
duration: 0
|
||||
})
|
||||
|
||||
// 添加拖动状态
|
||||
const [isDragging, setIsDragging] = useState(false)
|
||||
|
||||
// 监听TTS进度更新事件
|
||||
useEffect(() => {
|
||||
const handleProgressUpdate = (event: CustomEvent) => {
|
||||
const { messageId: playingMessageId, isPlaying, progress, currentTime, duration } = event.detail
|
||||
|
||||
console.log('TTS进度更新事件:', {
|
||||
playingMessageId,
|
||||
currentMessageId: messageId,
|
||||
isPlaying,
|
||||
progress,
|
||||
currentTime,
|
||||
duration
|
||||
})
|
||||
// 不需要每次都输出日志,避免控制台刷屏
|
||||
// 只在进度变化较大时输出日志,或者开始/结束时
|
||||
// 在拖动进度条时不输出日志
|
||||
// 完全关闭进度更新日志输出
|
||||
// if (!isDragging &&
|
||||
// playingMessageId === messageId &&
|
||||
// (
|
||||
// // 开始或结束播放
|
||||
// (isPlaying !== progressState.isPlaying) ||
|
||||
// // 每10%输出一次日志
|
||||
// (Math.floor(progress / 10) !== Math.floor(progressState.progress / 10))
|
||||
// )
|
||||
// ) {
|
||||
// console.log('TTS进度更新:', {
|
||||
// messageId: messageId.substring(0, 8),
|
||||
// isPlaying,
|
||||
// progress: Math.round(progress),
|
||||
// currentTime: Math.round(currentTime),
|
||||
// duration: Math.round(duration)
|
||||
// })
|
||||
// }
|
||||
|
||||
// 只有当前消息正在播放时才更新进度
|
||||
if (playingMessageId === messageId) {
|
||||
// 增加对playingMessageId的检查,确保它存在且不为空
|
||||
// 这样在语音通话模式下的开场白不会显示进度条
|
||||
if (playingMessageId && playingMessageId === messageId) {
|
||||
// 如果收到的是重置信号(duration为0),则强制设置为非播放状态
|
||||
if (duration === 0 && currentTime === 0 && progress === 0) {
|
||||
setProgressState({
|
||||
@ -64,7 +87,7 @@ const TTSProgressBar: React.FC<TTSProgressBarProps> = ({ messageId }) => {
|
||||
|
||||
// 如果停止播放,重置进度条状态
|
||||
if (!isPlaying && progressState.isPlaying) {
|
||||
console.log('收到TTS停止播放事件,重置进度条')
|
||||
// console.log('收到TTS停止播放事件,重置进度条')
|
||||
setProgressState({
|
||||
isPlaying: false,
|
||||
progress: 0,
|
||||
@ -78,18 +101,18 @@ const TTSProgressBar: React.FC<TTSProgressBarProps> = ({ messageId }) => {
|
||||
window.addEventListener('tts-progress-update', handleProgressUpdate as EventListener)
|
||||
window.addEventListener('tts-state-change', handleStateChange as EventListener)
|
||||
|
||||
console.log('添加TTS进度更新事件监听器,消息ID:', messageId)
|
||||
// console.log('添加TTS进度更新事件监听器,消息ID:', messageId)
|
||||
|
||||
// 组件卸载时移除事件监听器
|
||||
return () => {
|
||||
window.removeEventListener('tts-progress-update', handleProgressUpdate as EventListener)
|
||||
window.removeEventListener('tts-state-change', handleStateChange as EventListener)
|
||||
console.log('移除TTS进度更新事件监听器,消息ID:', messageId)
|
||||
// console.log('移除TTS进度更新事件监听器,消息ID:', messageId)
|
||||
}
|
||||
}, [messageId, progressState.isPlaying])
|
||||
}, [messageId, progressState.isPlaying, isDragging])
|
||||
|
||||
// 如果没有播放,不显示进度条
|
||||
if (!progressState.isPlaying) {
|
||||
// 如果没有播放或者设置为不显示进度条,则不显示
|
||||
if (!progressState.isPlaying || !showTTSProgressBar) {
|
||||
return null
|
||||
}
|
||||
|
||||
@ -106,7 +129,7 @@ const TTSProgressBar: React.FC<TTSProgressBarProps> = ({ messageId }) => {
|
||||
const seekPercentage = (clickPosition / trackWidth) * 100
|
||||
const seekTime = (seekPercentage / 100) * progressState.duration
|
||||
|
||||
console.log(`进度条点击: ${seekPercentage.toFixed(2)}%, 时间: ${seekTime.toFixed(2)}秒`)
|
||||
// console.log(`进度条点击: ${seekPercentage.toFixed(2)}%, 时间: ${seekTime.toFixed(2)}秒`)
|
||||
|
||||
// 调用TTS服务的seek方法
|
||||
import('@renderer/services/TTSService').then(({ default: TTSService }) => {
|
||||
@ -120,8 +143,8 @@ const TTSProgressBar: React.FC<TTSProgressBarProps> = ({ messageId }) => {
|
||||
e.preventDefault()
|
||||
e.stopPropagation() // 阻止事件冒泡
|
||||
|
||||
// 记录开始拖动状态
|
||||
let isDragging = true
|
||||
// 设置拖动状态为true
|
||||
setIsDragging(true)
|
||||
|
||||
const trackRect = e.currentTarget.getBoundingClientRect()
|
||||
const trackWidth = trackRect.width
|
||||
@ -145,7 +168,8 @@ const TTSProgressBar: React.FC<TTSProgressBarProps> = ({ messageId }) => {
|
||||
const handleMouseUp = (upEvent: MouseEvent) => {
|
||||
if (!isDragging) return
|
||||
|
||||
isDragging = false
|
||||
// 设置拖动状态为false
|
||||
setIsDragging(false)
|
||||
document.removeEventListener('mousemove', handleMouseMove)
|
||||
document.removeEventListener('mouseup', handleMouseUp)
|
||||
|
||||
@ -153,7 +177,7 @@ const TTSProgressBar: React.FC<TTSProgressBarProps> = ({ messageId }) => {
|
||||
const seekPercentage = (dragPosition / trackWidth) * 100
|
||||
const seekTime = (seekPercentage / 100) * progressState.duration
|
||||
|
||||
console.log(`拖动结束: ${seekPercentage.toFixed(2)}%, 时间: ${seekTime.toFixed(2)}秒`)
|
||||
// console.log(`拖动结束: ${seekPercentage.toFixed(2)}%, 时间: ${seekTime.toFixed(2)}秒`)
|
||||
|
||||
// 调用TTS服务的seek方法
|
||||
import('@renderer/services/TTSService').then(({ default: TTSService }) => {
|
||||
|
||||
@ -1,5 +1,66 @@
|
||||
import i18n from '@renderer/i18n'
|
||||
import dayjs from 'dayjs'
|
||||
|
||||
// 语音通话提示词(多语言支持)
|
||||
export const VOICE_CALL_PROMPTS: Record<string, string> = {
|
||||
'zh-CN': `当前是语音通话模式。请注意:
|
||||
1. 简洁直接地回答问题,避免冗长的引导和总结。
|
||||
2. 避免使用复杂的格式化内容,如表格、代码块、Markdown等。
|
||||
3. 使用自然、口语化的表达方式,就像与人对话一样。
|
||||
4. 如果需要列出要点,使用简单的数字或文字标记,而不是复杂的格式。
|
||||
5. 回答应该简短有力,便于用户通过语音理解。
|
||||
6. 避免使用特殊符号、表情符号、标点符号等,因为这些在语音播放时会影响理解。
|
||||
7. 使用完整的句子而非简单的关键词列表。
|
||||
8. 尽量使用常见词汇,避免生僻或专业术语,除非用户特别询问。`,
|
||||
'en-US': `This is voice call mode. Please note:
|
||||
1. Answer questions concisely and directly, avoiding lengthy introductions and summaries.
|
||||
2. Avoid complex formatted content such as tables, code blocks, Markdown, etc.
|
||||
3. Use natural, conversational language as if speaking to a person.
|
||||
4. If you need to list points, use simple numbers or text markers rather than complex formats.
|
||||
5. Responses should be brief and powerful, easy for users to understand through voice.
|
||||
6. Avoid special symbols, emojis, punctuation marks, etc., as these can affect comprehension during voice playback.
|
||||
7. Use complete sentences rather than simple keyword lists.
|
||||
8. Try to use common vocabulary, avoiding obscure or technical terms unless specifically asked by the user.`,
|
||||
'zh-TW': `當前是語音通話模式。請注意:
|
||||
1. 簡潔直接地回答問題,避免冗長的引導和總結。
|
||||
2. 避免使用複雜的格式化內容,如表格、代碼塊、Markdown等。
|
||||
3. 使用自然、口語化的表達方式,就像與人對話一樣。
|
||||
4. 如果需要列出要點,使用簡單的數字或文字標記,而不是複雜的格式。
|
||||
5. 回答應該簡短有力,便於用戶通過語音理解。
|
||||
6. 避免使用特殊符號、表情符號、標點符號等,因為這些在語音播放時會影響理解。
|
||||
7. 使用完整的句子而非簡單的關鍵詞列表。
|
||||
8. 盡量使用常見詞彙,避免生僻或專業術語,除非用戶特別詢問。`,
|
||||
'ja-JP': `これは音声通話モードです。ご注意ください:
|
||||
1. 質問に簡潔かつ直接的に答え、長い導入や要約を避けてください。
|
||||
2. 表、コードブロック、Markdownなどの複雑な書式付きコンテンツを避けてください。
|
||||
3. 人と話すように、自然で会話的な言葉を使ってください。
|
||||
4. ポイントをリストアップする必要がある場合は、複雑な形式ではなく、単純な数字やテキストマーカーを使用してください。
|
||||
5. 応答は簡潔で力強く、ユーザーが音声で理解しやすいものにしてください。
|
||||
6. 特殊記号、絵文字、句読点などは、音声再生中に理解に影響を与える可能性があるため、避けてください。
|
||||
7. 単純なキーワードリストではなく、完全な文を使用してください。
|
||||
8. ユーザーから特に質問されない限り、わかりにくい専門用語を避け、一般的な語彙を使用するようにしてください。`,
|
||||
'ru-RU': `Это режим голосового вызова. Обратите внимание:
|
||||
1. Отвечайте на вопросы кратко и прямо, избегая длинных введений и резюме.
|
||||
2. Избегайте сложного форматированного содержания, такого как таблицы, блоки кода, Markdown и т.д.
|
||||
3. Используйте естественный, разговорный язык, как при разговоре с человеком.
|
||||
4. Если вам нужно перечислить пункты, используйте простые цифры или текстовые маркеры, а не сложные форматы.
|
||||
5. Ответы должны быть краткими и содержательными, легкими для понимания пользователем через голос.
|
||||
6. Избегайте специальных символов, эмодзи, знаков препинания и т.д., так как они могут затруднить понимание при воспроизведении голосом.
|
||||
7. Используйте полные предложения, а не простые списки ключевых слов.
|
||||
8. Старайтесь использовать общеупотребительную лексику, избегая малоизвестных или технических терминов, если пользователь специально не спрашивает о них.`
|
||||
// 可以添加更多语言...
|
||||
}
|
||||
|
||||
// 获取当前语言的默认语音通话提示词
|
||||
export function getDefaultVoiceCallPrompt(): string {
|
||||
const language = i18n.language || 'en-US'
|
||||
// 如果没有对应语言的提示词,使用英文提示词作为后备
|
||||
return VOICE_CALL_PROMPTS[language] || VOICE_CALL_PROMPTS['en-US']
|
||||
}
|
||||
|
||||
// 为了向后兼容,保留原来的常量
|
||||
export const DEFAULT_VOICE_CALL_PROMPT = getDefaultVoiceCallPrompt()
|
||||
|
||||
export const AGENT_PROMPT = `
|
||||
You are a Prompt Generator. You will integrate user input information into a structured Prompt using Markdown syntax. Please do not use code blocks for output, display directly!
|
||||
|
||||
|
||||
@ -1418,7 +1418,9 @@
|
||||
"filter.markdown": "Filter Markdown",
|
||||
"filter.code_blocks": "Filter code blocks",
|
||||
"filter.html_tags": "Filter HTML tags",
|
||||
"filter.emojis": "Filter emojis",
|
||||
"max_text_length": "Maximum text length",
|
||||
"show_progress_bar": "Show TTS progress bar",
|
||||
"test": "Test Speech",
|
||||
"help": "Text-to-speech functionality supports converting text to natural-sounding speech.",
|
||||
"learn_more": "Learn more",
|
||||
@ -1499,7 +1501,9 @@
|
||||
"transcribe_failed": "Failed to transcribe speech",
|
||||
"no_api_key": "[to be translated]:未设置API密钥",
|
||||
"browser_not_support": "[to be translated]:浏览器不支持语音识别"
|
||||
}
|
||||
},
|
||||
"auto_start_server": "[to be translated]:启动应用自动开启服务器",
|
||||
"auto_start_server.help": "[to be translated]:启用后,应用启动时会自动开启语音识别服务器"
|
||||
},
|
||||
"voice": {
|
||||
"title": "Voice Features",
|
||||
@ -1514,6 +1518,16 @@
|
||||
"model.select": "Select Model",
|
||||
"model.current": "Current Model: {{model}}",
|
||||
"model.info": "Select the AI model for voice calls. Different models may provide different voice interaction experiences",
|
||||
"welcome_message": "Hello, I'm your AI assistant. Please press and hold the talk button to start a conversation.",
|
||||
"prompt": {
|
||||
"label": "Voice Call Prompt",
|
||||
"placeholder": "Enter voice call prompt",
|
||||
"save": "Save",
|
||||
"reset": "Reset",
|
||||
"saved": "Prompt saved",
|
||||
"reset_done": "Prompt reset",
|
||||
"info": "This prompt will guide the AI's responses in voice call mode"
|
||||
},
|
||||
"asr_tts_info": "Voice call uses the Speech Recognition (ASR) and Text-to-Speech (TTS) settings above",
|
||||
"test": "Test Voice Call",
|
||||
"test_info": "Please use the voice call button on the right side of the input box to test"
|
||||
|
||||
@ -1362,66 +1362,74 @@
|
||||
"error": {
|
||||
"not_enabled": "音声合成が有効になっていません",
|
||||
"no_edge_voice": "ブラウザ TTSの音声が選択されていません",
|
||||
"no_api_key": "[to be translated]:未设置API密钥",
|
||||
"browser_not_support": "[to be translated]:浏览器不支持语音合成",
|
||||
"no_voice": "[to be translated]:未选择音色",
|
||||
"no_model": "[to be translated]:未选择模型",
|
||||
"synthesis_failed": "[to be translated]:语音合成失败",
|
||||
"play_failed": "[to be translated]:语音播放失败",
|
||||
"empty_text": "[to be translated]:文本为空",
|
||||
"general": "[to be translated]:语音合成出现错误",
|
||||
"unsupported_service_type": "[to be translated]:不支持的服务类型: {{serviceType}}"
|
||||
"no_api_key": "APIキーが設定されていません",
|
||||
"browser_not_support": "ブラウザが音声合成をサポートしていません",
|
||||
"no_voice": "音声が選択されていません",
|
||||
"no_model": "モデルが選択されていません",
|
||||
"synthesis_failed": "音声合成に失敗しました",
|
||||
"play_failed": "音声再生に失敗しました",
|
||||
"empty_text": "テキストが空です",
|
||||
"general": "音声合成エラーが発生しました",
|
||||
"unsupported_service_type": "サポートされていないサービスタイプ: {{serviceType}}"
|
||||
},
|
||||
"help": "OpenAIのTTS APIを使用するには、APIキーが必要です。ブラウザ TTSはブラウザの機能を使用するため、APIキーは不要です。",
|
||||
"learn_more": "詳細はこちら",
|
||||
"tab_title": "[to be translated]:语音合成",
|
||||
"service_type.refresh": "[to be translated]:刷新TTS服务类型设置",
|
||||
"service_type.refreshed": "[to be translated]:已刷新TTS服务类型设置",
|
||||
"api_key": "[to be translated]:API密钥",
|
||||
"api_key.placeholder": "[to be translated]:请输入OpenAI API密钥",
|
||||
"api_url": "[to be translated]:API地址",
|
||||
"api_url.placeholder": "[to be translated]:例如:https://api.openai.com/v1/audio/speech",
|
||||
"edge_voice": "[to be translated]:浏览器 TTS音色",
|
||||
"edge_voice.loading": "[to be translated]:加载中...",
|
||||
"edge_voice.refresh": "[to be translated]:刷新可用音色列表",
|
||||
"edge_voice.not_found": "[to be translated]:未找到匹配的音色",
|
||||
"voice": "[to be translated]:音色",
|
||||
"voice.placeholder": "[to be translated]:请选择音色",
|
||||
"voice_input_placeholder": "[to be translated]:输入音色",
|
||||
"voice_add": "[to be translated]:添加",
|
||||
"voice_empty": "[to be translated]:暂无自定义音色,请在下方添加",
|
||||
"model": "[to be translated]:模型",
|
||||
"model.placeholder": "[to be translated]:请选择模型",
|
||||
"model_input_placeholder": "[to be translated]:输入模型",
|
||||
"model_add": "[to be translated]:添加",
|
||||
"model_empty": "[to be translated]:暂无自定义模型,请在下方添加",
|
||||
"filter_options": "[to be translated]:过滤选项",
|
||||
"filter.thinking_process": "[to be translated]:过滤思考过程",
|
||||
"filter.markdown": "[to be translated]:过滤Markdown标记",
|
||||
"filter.code_blocks": "[to be translated]:过滤代码块",
|
||||
"filter.html_tags": "[to be translated]:过滤HTML标签",
|
||||
"max_text_length": "[to be translated]:最大文本长度",
|
||||
"service_type.siliconflow": "[to be translated]:硅基流动",
|
||||
"service_type.mstts": "[to be translated]:免费在线 TTS",
|
||||
"siliconflow_api_key": "[to be translated]:硅基流动API密钥",
|
||||
"siliconflow_api_key.placeholder": "[to be translated]:请输入硅基流动API密钥",
|
||||
"siliconflow_api_url": "[to be translated]:硅基流动API地址",
|
||||
"siliconflow_api_url.placeholder": "[to be translated]:例如:https://api.siliconflow.cn/v1/audio/speech",
|
||||
"siliconflow_voice": "[to be translated]:硅基流动音色",
|
||||
"siliconflow_voice.placeholder": "[to be translated]:请选择音色",
|
||||
"siliconflow_model": "[to be translated]:硅基流动模型",
|
||||
"siliconflow_model.placeholder": "[to be translated]:请选择模型",
|
||||
"siliconflow_response_format": "[to be translated]:响应格式",
|
||||
"siliconflow_response_format.placeholder": "[to be translated]:默认为mp3",
|
||||
"siliconflow_speed": "[to be translated]:语速",
|
||||
"siliconflow_speed.placeholder": "[to be translated]:默认为1.0",
|
||||
"edge_voice.available_count": "[to be translated]:可用语音: {{count}}个",
|
||||
"edge_voice.refreshing": "[to be translated]:正在刷新语音列表...",
|
||||
"edge_voice.refreshed": "[to be translated]:语音列表已刷新",
|
||||
"mstts.voice": "[to be translated]:免费在线 TTS音色",
|
||||
"mstts.output_format": "[to be translated]:输出格式",
|
||||
"mstts.info": "[to be translated]:免费在线TTS服务不需要API密钥,完全免费使用。",
|
||||
"error.no_mstts_voice": "[to be translated]:未设置免费在线 TTS音色"
|
||||
"tab_title": "音声合成",
|
||||
"service_type.refresh": "TTS サービスタイプ設定を更新",
|
||||
"service_type.refreshed": "TTS サービスタイプ設定が更新されました",
|
||||
"api_key": "API キー",
|
||||
"api_key.placeholder": "OpenAI API キーを入力してください",
|
||||
"api_url": "API アドレス",
|
||||
"api_url.placeholder": "例:https://api.openai.com/v1/audio/speech",
|
||||
"edge_voice": "ブラウザ TTS 音声",
|
||||
"edge_voice.loading": "読み込み中...",
|
||||
"edge_voice.refresh": "利用可能な音声リストを更新",
|
||||
"edge_voice.not_found": "一致する音声が見つかりません",
|
||||
"voice": "音声",
|
||||
"voice.placeholder": "音声を選択してください",
|
||||
"voice_input_placeholder": "音声を入力",
|
||||
"voice_add": "追加",
|
||||
"voice_empty": "カスタム音声がありません。下に追加してください",
|
||||
"model": "モデル",
|
||||
"model.placeholder": "モデルを選択してください",
|
||||
"model_input_placeholder": "モデルを入力",
|
||||
"model_add": "追加",
|
||||
"model_empty": "カスタムモデルがありません。下に追加してください",
|
||||
"filter_options": "フィルターオプション",
|
||||
"filter.thinking_process": "思考プロセスをフィルター",
|
||||
"filter.markdown": "Markdownタグをフィルター",
|
||||
"filter.code_blocks": "コードブロックをフィルター",
|
||||
"filter.html_tags": "HTMLタグをフィルター",
|
||||
"max_text_length": "最大テキスト長",
|
||||
"service_type.siliconflow": "シリコンフロー",
|
||||
"service_type.mstts": "無料オンライン TTS",
|
||||
"siliconflow_api_key": "シリコンフロー API キー",
|
||||
"siliconflow_api_key.placeholder": "シリコンフロー API キーを入力してください",
|
||||
"siliconflow_api_url": "シリコンフロー API アドレス",
|
||||
"siliconflow_api_url.placeholder": "例:https://api.siliconflow.cn/v1/audio/speech",
|
||||
"siliconflow_voice": "シリコンフロー音声",
|
||||
"siliconflow_voice.placeholder": "音声を選択してください",
|
||||
"siliconflow_model": "シリコンフローモデル",
|
||||
"siliconflow_model.placeholder": "モデルを選択してください",
|
||||
"siliconflow_response_format": "レスポンス形式",
|
||||
"siliconflow_response_format.placeholder": "デフォルトはmp3",
|
||||
"siliconflow_speed": "話す速度",
|
||||
"siliconflow_speed.placeholder": "デフォルトは1.0",
|
||||
"edge_voice.available_count": "利用可能な音声: {{count}}個",
|
||||
"edge_voice.refreshing": "音声リストを更新中...",
|
||||
"edge_voice.refreshed": "音声リストが更新されました",
|
||||
"mstts.voice": "無料オンライン TTS 音声",
|
||||
"mstts.output_format": "出力形式",
|
||||
"mstts.info": "無料オンラインTTSサービスはAPIキーが不要で、完全に無料で使用できます。",
|
||||
"error.no_mstts_voice": "無料オンライン TTS 音声が設定されていません",
|
||||
"play": "音声を再生",
|
||||
"stop": "再生を停止",
|
||||
"speak": "音声を再生",
|
||||
"stop_global": "すべての音声再生を停止",
|
||||
"stopped": "音声再生を停止しました",
|
||||
"segmented": "分割",
|
||||
"segmented_play": "分割再生",
|
||||
"segmented_playback": "分割再生"
|
||||
},
|
||||
"asr": {
|
||||
"title": "音声認識",
|
||||
@ -1467,26 +1475,40 @@
|
||||
"not_enabled": "音声認識が有効になっていません",
|
||||
"start_failed": "録音の開始に失敗しました",
|
||||
"transcribe_failed": "音声の文字起こしに失敗しました",
|
||||
"no_api_key": "[to be translated]:未设置API密钥",
|
||||
"browser_not_support": "[to be translated]:浏览器不支持语音识别"
|
||||
}
|
||||
"no_api_key": "APIキーが設定されていません",
|
||||
"browser_not_support": "ブラウザが音声認識をサポートしていません"
|
||||
},
|
||||
"auto_start_server": "アプリ起動時にサーバーを自動起動",
|
||||
"auto_start_server.help": "有効にすると、アプリ起動時に音声認識サーバーが自動的に起動します",
|
||||
"language": "認識言語"
|
||||
},
|
||||
"voice": {
|
||||
"title": "[to be translated]:语音功能",
|
||||
"help": "[to be translated]:语音功能包括文本转语音(TTS)和语音识别(ASR)。",
|
||||
"learn_more": "[to be translated]:了解更多"
|
||||
"title": "音声機能",
|
||||
"help": "音声機能にはテキスト読み上げ(TTS)と音声認識(ASR)が含まれます。",
|
||||
"learn_more": "詳細を見る"
|
||||
},
|
||||
"voice_call": {
|
||||
"tab_title": "[to be translated]:通话功能",
|
||||
"enable": "[to be translated]:启用语音通话",
|
||||
"enable.help": "[to be translated]:启用后可以使用语音通话功能与AI进行对话",
|
||||
"model": "[to be translated]:通话模型",
|
||||
"model.select": "[to be translated]:选择模型",
|
||||
"model.current": "[to be translated]:当前模型: {{model}}",
|
||||
"model.info": "[to be translated]:选择用于语音通话的AI模型,不同模型可能有不同的语音交互体验",
|
||||
"asr_tts_info": "[to be translated]:语音通话使用上面的语音识别(ASR)和语音合成(TTS)设置",
|
||||
"test": "[to be translated]:测试通话",
|
||||
"test_info": "[to be translated]:请使用输入框右侧的语音通话按钮进行测试"
|
||||
"tab_title": "通話機能",
|
||||
"enable": "音声通話を有効にする",
|
||||
"enable.help": "有効にすると、音声通話機能を使用してAIと対話できます",
|
||||
"model": "通話モデル",
|
||||
"model.select": "モデルを選択",
|
||||
"model.current": "現在のモデル: {{model}}",
|
||||
"model.info": "音声通話用のAIモデルを選択します。モデルによって音声対話の体験が異なる場合があります",
|
||||
"welcome_message": "こんにちは、AIアシスタントです。会話を始めるには、ボタンを長押ししてください。",
|
||||
"prompt": {
|
||||
"label": "音声通話プロンプト",
|
||||
"placeholder": "音声通話プロンプトを入力",
|
||||
"save": "保存",
|
||||
"reset": "リセット",
|
||||
"saved": "プロンプトが保存されました",
|
||||
"reset_done": "プロンプトがリセットされました",
|
||||
"info": "このプロンプトは音声通話モードでのAIの応答方法を指導します",
|
||||
"language_info": "リセットボタンをクリックすると、現在の言語のデフォルトプロンプトが取得されます"
|
||||
},
|
||||
"asr_tts_info": "音声通話は上記の音声認識(ASR)と音声合成(TTS)の設定を使用します",
|
||||
"test": "音声通話テスト",
|
||||
"test_info": "入力ボックスの右側にある音声通話ボタンを使用してテストしてください"
|
||||
}
|
||||
},
|
||||
"translate": {
|
||||
@ -1529,26 +1551,26 @@
|
||||
"visualization": "可視化"
|
||||
},
|
||||
"voice_call": {
|
||||
"title": "[to be translated]:语音通话",
|
||||
"start": "[to be translated]:开始语音通话",
|
||||
"end": "[to be translated]:结束通话",
|
||||
"mute": "[to be translated]:静音",
|
||||
"unmute": "[to be translated]:取消静音",
|
||||
"pause": "[to be translated]:暂停",
|
||||
"resume": "[to be translated]:继续",
|
||||
"you": "[to be translated]:您",
|
||||
"ai": "[to be translated]:AI",
|
||||
"press_to_talk": "[to be translated]:长按说话",
|
||||
"release_to_send": "[to be translated]:松开发送",
|
||||
"initialization_failed": "[to be translated]:初始化语音通话失败",
|
||||
"error": "[to be translated]:语音通话出错",
|
||||
"initializing": "[to be translated]:正在初始化语音通话...",
|
||||
"ready": "[to be translated]:语音通话已就绪",
|
||||
"shortcut_key_setting": "[to be translated]:语音识别快捷键设置",
|
||||
"press_any_key": "[to be translated]:请按任意键...",
|
||||
"save": "[to be translated]:保存",
|
||||
"cancel": "[to be translated]:取消",
|
||||
"shortcut_key_tip": "[to be translated]:按下此快捷键开始录音,松开快捷键结束录音并发送"
|
||||
"title": "音声通話",
|
||||
"start": "音声通話を開始",
|
||||
"end": "通話を終了",
|
||||
"mute": "ミュート",
|
||||
"unmute": "ミュート解除",
|
||||
"pause": "一時停止",
|
||||
"resume": "再開",
|
||||
"you": "あなた",
|
||||
"ai": "AI",
|
||||
"press_to_talk": "長押しして話す",
|
||||
"release_to_send": "離すと送信",
|
||||
"initialization_failed": "音声通話の初期化に失敗しました",
|
||||
"error": "音声通話エラー",
|
||||
"initializing": "音声通話を初期化中...",
|
||||
"ready": "音声通話の準備が完了しました",
|
||||
"shortcut_key_setting": "音声認識ショートカットキー設定",
|
||||
"press_any_key": "任意のキーを押してください...",
|
||||
"save": "保存",
|
||||
"cancel": "キャンセル",
|
||||
"shortcut_key_tip": "このショートカットキーを押すと録音が始まり、キーを離すと録音が終了して送信されます"
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1421,7 +1421,15 @@
|
||||
"mstts.voice": "[to be translated]:免费在线 TTS音色",
|
||||
"mstts.output_format": "[to be translated]:输出格式",
|
||||
"mstts.info": "[to be translated]:免费在线TTS服务不需要API密钥,完全免费使用。",
|
||||
"error.no_mstts_voice": "[to be translated]:未设置免费在线 TTS音色"
|
||||
"error.no_mstts_voice": "[to be translated]:未设置免费在线 TTS音色",
|
||||
"play": "[to be translated]:播放语音",
|
||||
"stop": "[to be translated]:停止播放",
|
||||
"speak": "[to be translated]:播放语音",
|
||||
"stop_global": "[to be translated]:停止所有语音播放",
|
||||
"stopped": "[to be translated]:已停止语音播放",
|
||||
"segmented": "[to be translated]:分段",
|
||||
"segmented_play": "[to be translated]:分段播放",
|
||||
"segmented_playback": "[to be translated]:分段播放"
|
||||
},
|
||||
"voice": {
|
||||
"title": "[to be translated]:语音功能",
|
||||
@ -1474,7 +1482,9 @@
|
||||
"browser_not_support": "[to be translated]:浏览器不支持语音识别",
|
||||
"start_failed": "[to be translated]:开始录音失败",
|
||||
"transcribe_failed": "[to be translated]:语音识别失败"
|
||||
}
|
||||
},
|
||||
"auto_start_server": "[to be translated]:启动应用自动开启服务器",
|
||||
"auto_start_server.help": "[to be translated]:启用后,应用启动时会自动开启语音识别服务器"
|
||||
},
|
||||
"voice_call": {
|
||||
"tab_title": "[to be translated]:通话功能",
|
||||
@ -1484,9 +1494,19 @@
|
||||
"model.select": "[to be translated]:选择模型",
|
||||
"model.current": "[to be translated]:当前模型: {{model}}",
|
||||
"model.info": "[to be translated]:选择用于语音通话的AI模型,不同模型可能有不同的语音交互体验",
|
||||
"asr_tts_info": "[to be translated]:语音通话使用上面的语音识别(ASR)和语音合成(TTS)设置",
|
||||
"test": "[to be translated]:测试通话",
|
||||
"test_info": "[to be translated]:请使用输入框右侧的语音通话按钮进行测试"
|
||||
"prompt": {
|
||||
"label": "Подсказка для голосового вызова",
|
||||
"placeholder": "Введите подсказку для голосового вызова",
|
||||
"save": "Сохранить",
|
||||
"reset": "Сбросить",
|
||||
"saved": "Подсказка сохранена",
|
||||
"reset_done": "Подсказка сброшена",
|
||||
"info": "Эта подсказка будет направлять ответы ИИ в режиме голосового вызова",
|
||||
"language_info": "Нажмите кнопку сброса, чтобы получить стандартную подсказку для текущего языка"
|
||||
},
|
||||
"asr_tts_info": "Голосовой вызов использует настройки распознавания речи (ASR) и синтеза речи (TTS), указанные выше",
|
||||
"test": "Тестировать голосовой вызов",
|
||||
"test_info": "Используйте кнопку голосового вызова справа от поля ввода для тестирования"
|
||||
}
|
||||
},
|
||||
"translate": {
|
||||
|
||||
@ -1432,7 +1432,9 @@
|
||||
"filter.markdown": "过滤Markdown标记",
|
||||
"filter.code_blocks": "过滤代码块",
|
||||
"filter.html_tags": "过滤HTML标签",
|
||||
"filter.emojis": "过滤表情符号",
|
||||
"max_text_length": "最大文本长度",
|
||||
"show_progress_bar": "显示TTS进度条",
|
||||
"test": "测试语音",
|
||||
"help": "语音合成功能支持将文本转换为自然语音。",
|
||||
"learn_more": "了解更多",
|
||||
@ -1516,6 +1518,16 @@
|
||||
"model.select": "选择模型",
|
||||
"model.current": "当前模型: {{model}}",
|
||||
"model.info": "选择用于语音通话的AI模型,不同模型可能有不同的语音交互体验",
|
||||
"welcome_message": "您好,我是您的AI助手,请长按说话按钮进行对话。",
|
||||
"prompt": {
|
||||
"label": "语音通话提示词",
|
||||
"placeholder": "请输入语音通话提示词",
|
||||
"save": "保存",
|
||||
"reset": "重置",
|
||||
"saved": "提示词已保存",
|
||||
"reset_done": "提示词已重置",
|
||||
"info": "此提示词将指导AI在语音通话模式下的回复方式"
|
||||
},
|
||||
"asr_tts_info": "语音通话使用上面的语音识别(ASR)和语音合成(TTS)设置",
|
||||
"test": "测试通话",
|
||||
"test_info": "请使用输入框右侧的语音通话按钮进行测试"
|
||||
|
||||
1576
src/renderer/src/i18n/locales/zh-cn.json.bak
Normal file
1576
src/renderer/src/i18n/locales/zh-cn.json.bak
Normal file
File diff suppressed because it is too large
Load Diff
@ -1421,7 +1421,15 @@
|
||||
"mstts.voice": "[to be translated]:免费在线 TTS音色",
|
||||
"mstts.output_format": "[to be translated]:输出格式",
|
||||
"mstts.info": "[to be translated]:免费在线TTS服务不需要API密钥,完全免费使用。",
|
||||
"error.no_mstts_voice": "[to be translated]:未设置免费在线 TTS音色"
|
||||
"error.no_mstts_voice": "[to be translated]:未设置免费在线 TTS音色",
|
||||
"play": "[to be translated]:播放语音",
|
||||
"stop": "[to be translated]:停止播放",
|
||||
"speak": "[to be translated]:播放语音",
|
||||
"stop_global": "[to be translated]:停止所有语音播放",
|
||||
"stopped": "[to be translated]:已停止语音播放",
|
||||
"segmented": "[to be translated]:分段",
|
||||
"segmented_play": "[to be translated]:分段播放",
|
||||
"segmented_playback": "[to be translated]:分段播放"
|
||||
},
|
||||
"voice": {
|
||||
"title": "[to be translated]:语音功能",
|
||||
@ -1474,7 +1482,9 @@
|
||||
"browser_not_support": "[to be translated]:浏览器不支持语音识别",
|
||||
"start_failed": "[to be translated]:开始录音失败",
|
||||
"transcribe_failed": "[to be translated]:语音识别失败"
|
||||
}
|
||||
},
|
||||
"auto_start_server": "[to be translated]:启动应用自动开启服务器",
|
||||
"auto_start_server.help": "[to be translated]:启用后,应用启动时会自动开启语音识别服务器"
|
||||
},
|
||||
"voice_call": {
|
||||
"tab_title": "[to be translated]:通话功能",
|
||||
@ -1484,9 +1494,19 @@
|
||||
"model.select": "[to be translated]:选择模型",
|
||||
"model.current": "[to be translated]:当前模型: {{model}}",
|
||||
"model.info": "[to be translated]:选择用于语音通话的AI模型,不同模型可能有不同的语音交互体验",
|
||||
"asr_tts_info": "[to be translated]:语音通话使用上面的语音识别(ASR)和语音合成(TTS)设置",
|
||||
"test": "[to be translated]:测试通话",
|
||||
"test_info": "[to be translated]:请使用输入框右侧的语音通话按钮进行测试"
|
||||
"prompt": {
|
||||
"label": "語音通話提示詞",
|
||||
"placeholder": "請輸入語音通話提示詞",
|
||||
"save": "保存",
|
||||
"reset": "重置",
|
||||
"saved": "提示詞已保存",
|
||||
"reset_done": "提示詞已重置",
|
||||
"info": "此提示詞將指導AI在語音通話模式下的回覆方式",
|
||||
"language_info": "點擊重置按鈕可獲取當前語言的預設提示詞"
|
||||
},
|
||||
"asr_tts_info": "語音通話使用上面的語音識別(ASR)和語音合成(TTS)設置",
|
||||
"test": "測試通話",
|
||||
"test_info": "請使用輸入框右側的語音通話按鈕進行測試"
|
||||
}
|
||||
},
|
||||
"translate": {
|
||||
|
||||
@ -18,6 +18,7 @@ import { QuickPanelListItem, QuickPanelView, useQuickPanel } from '@renderer/com
|
||||
import TranslateButton from '@renderer/components/TranslateButton'
|
||||
import VoiceCallButton from '@renderer/components/VoiceCallButton'
|
||||
import { isGenerateImageModel, isVisionModel, isWebSearchModel } from '@renderer/config/models'
|
||||
import { getDefaultVoiceCallPrompt } from '@renderer/config/prompts'
|
||||
import db from '@renderer/databases'
|
||||
import { useAssistant } from '@renderer/hooks/useAssistant'
|
||||
import { useKnowledgeBases } from '@renderer/hooks/useKnowledge'
|
||||
@ -804,22 +805,17 @@ const Inputbar: FC<Props> = ({ assistant: _assistant, setActiveTopic, topic }) =
|
||||
)
|
||||
}
|
||||
|
||||
// 添加语音通话专属提示词
|
||||
const voiceCallPrompt = `当前是语音通话模式。请注意:
|
||||
1. 简洁直接地回答问题,避免冗长的引导和总结。
|
||||
2. 避免使用复杂的格式化内容,如表格、代码块、Markdown等。
|
||||
3. 使用自然、口语化的表达方式,就像与人对话一样。
|
||||
4. 如果需要列出要点,使用简单的数字或文字标记,而不是复杂的格式。
|
||||
5. 回答应该简短有力,便于用户通过语音理解。
|
||||
6. 避免使用特殊符号、表情符号、标点符号等,因为这些在语音播放时会影响理解。
|
||||
7. 使用完整的句子而非简单的关键词列表。
|
||||
8. 尽量使用常见词汇,避免生僻或专业术语,除非用户特别询问。`
|
||||
// 获取用户自定义提示词
|
||||
const { voiceCallPrompt } = store.getState().settings
|
||||
|
||||
// 使用自定义提示词或当前语言的默认提示词
|
||||
const promptToUse = voiceCallPrompt || getDefaultVoiceCallPrompt()
|
||||
|
||||
// 如果助手已经有提示词,则在其后添加语音通话专属提示词
|
||||
if (assistantToUse.prompt) {
|
||||
assistantToUse.prompt += '\n\n' + voiceCallPrompt
|
||||
assistantToUse.prompt += '\n\n' + promptToUse
|
||||
} else {
|
||||
assistantToUse.prompt = voiceCallPrompt
|
||||
assistantToUse.prompt = promptToUse
|
||||
}
|
||||
|
||||
console.log('为语音通话消息添加了专属提示词')
|
||||
|
||||
@ -7,6 +7,7 @@ import {
|
||||
setAsrApiUrl,
|
||||
setAsrAutoStartServer,
|
||||
setAsrEnabled,
|
||||
setAsrLanguage,
|
||||
setAsrModel,
|
||||
setAsrServiceType
|
||||
} from '@renderer/store/settings'
|
||||
@ -30,6 +31,7 @@ const ASRSettings: FC = () => {
|
||||
const asrApiUrl = useSelector((state: any) => state.settings.asrApiUrl)
|
||||
const asrModel = useSelector((state: any) => state.settings.asrModel || 'whisper-1')
|
||||
const asrAutoStartServer = useSelector((state: any) => state.settings.asrAutoStartServer)
|
||||
const asrLanguage = useSelector((state: any) => state.settings.asrLanguage || 'zh-CN')
|
||||
|
||||
// 检查服务器状态
|
||||
useEffect(() => {
|
||||
@ -48,6 +50,20 @@ const ASRSettings: FC = () => {
|
||||
// 模型选项
|
||||
const modelOptions = [{ label: 'whisper-1', value: 'whisper-1' }]
|
||||
|
||||
// 语言选项
|
||||
const languageOptions = [
|
||||
{ label: '中文 (Chinese)', value: 'zh-CN' },
|
||||
{ label: 'English', value: 'en-US' },
|
||||
{ label: '日本語 (Japanese)', value: 'ja-JP' },
|
||||
{ label: 'Русский (Russian)', value: 'ru-RU' },
|
||||
{ label: 'Français (French)', value: 'fr-FR' },
|
||||
{ label: 'Deutsch (German)', value: 'de-DE' },
|
||||
{ label: 'Español (Spanish)', value: 'es-ES' },
|
||||
{ label: 'Italiano (Italian)', value: 'it-IT' },
|
||||
{ label: 'Português (Portuguese)', value: 'pt-PT' },
|
||||
{ label: '한국어 (Korean)', value: 'ko-KR' }
|
||||
]
|
||||
|
||||
return (
|
||||
<Container>
|
||||
<Form layout="vertical">
|
||||
@ -154,7 +170,7 @@ const ASRSettings: FC = () => {
|
||||
<Button
|
||||
type="primary"
|
||||
icon={<GlobalOutlined />}
|
||||
onClick={() => ASRServerService.openServerPage()}
|
||||
onClick={() => window.open('http://localhost:34515', '_blank')}
|
||||
disabled={!asrEnabled || !isServerRunning}>
|
||||
{t('settings.asr.open_browser')}
|
||||
</Button>
|
||||
@ -187,6 +203,19 @@ const ASRSettings: FC = () => {
|
||||
|
||||
<BrowserTip>{t('settings.asr.local.browser_tip')}</BrowserTip>
|
||||
|
||||
{/* 语言选择 */}
|
||||
<Form.Item label={t('settings.asr.language', { defaultValue: '语言' })} style={{ marginTop: 16 }}>
|
||||
<Select
|
||||
value={asrLanguage}
|
||||
onChange={(value) => dispatch(setAsrLanguage(value))}
|
||||
options={languageOptions}
|
||||
disabled={!asrEnabled}
|
||||
style={{ width: '100%' }}
|
||||
showSearch
|
||||
optionFilterProp="label"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
{/* 启动应用自动开启服务器 */}
|
||||
<Form.Item style={{ marginTop: 16 }}>
|
||||
<Space>
|
||||
|
||||
@ -8,6 +8,7 @@ import {
|
||||
removeTtsCustomModel,
|
||||
removeTtsCustomVoice,
|
||||
resetTtsCustomValues,
|
||||
setShowTTSProgressBar,
|
||||
setTtsApiKey,
|
||||
setTtsApiUrl,
|
||||
setTtsEdgeVoice,
|
||||
@ -148,14 +149,28 @@ const TTSSettings: FC = () => {
|
||||
const ttsEdgeVoice = settings.ttsEdgeVoice || 'zh-CN-XiaoxiaoNeural'
|
||||
const ttsCustomVoices = settings.ttsCustomVoices || []
|
||||
const ttsCustomModels = settings.ttsCustomModels || []
|
||||
const showTTSProgressBar = settings.showTTSProgressBar
|
||||
// 免费在线TTS设置
|
||||
const ttsMsVoice = settings.ttsMsVoice || 'zh-CN-XiaoxiaoNeural'
|
||||
const ttsMsOutputFormat = settings.ttsMsOutputFormat || 'audio-24khz-48kbitrate-mono-mp3'
|
||||
|
||||
// 确保免费在线TTS设置有默认值
|
||||
useEffect(() => {
|
||||
if (ttsServiceType === 'mstts') {
|
||||
if (!settings.ttsMsVoice) {
|
||||
dispatch(setTtsMsVoice('zh-CN-XiaoxiaoNeural'))
|
||||
}
|
||||
if (!settings.ttsMsOutputFormat) {
|
||||
dispatch(setTtsMsOutputFormat('audio-24khz-48kbitrate-mono-mp3'))
|
||||
}
|
||||
}
|
||||
}, [ttsServiceType, settings.ttsMsVoice, settings.ttsMsOutputFormat, dispatch])
|
||||
const ttsFilterOptions = settings.ttsFilterOptions || {
|
||||
filterThinkingProcess: true,
|
||||
filterMarkdown: true,
|
||||
filterCodeBlocks: true,
|
||||
filterHtmlTags: true,
|
||||
filterEmojis: true,
|
||||
maxTextLength: 4000
|
||||
}
|
||||
|
||||
@ -370,6 +385,16 @@ const TTSSettings: FC = () => {
|
||||
return
|
||||
}
|
||||
|
||||
// 如果是免费在线TTS,确保音色已设置
|
||||
if (ttsServiceType === 'mstts' && !ttsMsVoice) {
|
||||
// 自动设置默认音色
|
||||
dispatch(setTtsMsVoice('zh-CN-XiaoxiaoNeural'))
|
||||
window.message.info({
|
||||
content: t('settings.tts.mstts.auto_set_voice', { defaultValue: '已自动设置默认音色' }),
|
||||
key: 'tts-test'
|
||||
})
|
||||
}
|
||||
|
||||
// 强制刷新状态,确保使用最新的设置
|
||||
// 先获取当前的服务类型
|
||||
const currentType = store.getState().settings.ttsServiceType || 'openai'
|
||||
@ -910,6 +935,14 @@ const TTSSettings: FC = () => {
|
||||
|
||||
{/* TTS过滤选项 */}
|
||||
<Form.Item label={t('settings.tts.filter_options')} style={{ marginTop: 24, marginBottom: 8 }}>
|
||||
<FilterOptionItem>
|
||||
<Switch
|
||||
checked={showTTSProgressBar}
|
||||
onChange={(checked) => dispatch(setShowTTSProgressBar(checked))}
|
||||
disabled={!ttsEnabled}
|
||||
/>{' '}
|
||||
{t('settings.tts.show_progress_bar', { defaultValue: '显示TTS进度条' })}
|
||||
</FilterOptionItem>
|
||||
<FilterOptionItem>
|
||||
<Switch
|
||||
checked={ttsFilterOptions.filterThinkingProcess}
|
||||
@ -942,6 +975,14 @@ const TTSSettings: FC = () => {
|
||||
/>{' '}
|
||||
{t('settings.tts.filter.html_tags')}
|
||||
</FilterOptionItem>
|
||||
<FilterOptionItem>
|
||||
<Switch
|
||||
checked={ttsFilterOptions.filterEmojis}
|
||||
onChange={(checked) => dispatch(setTtsFilterOptions({ filterEmojis: checked }))}
|
||||
disabled={!ttsEnabled}
|
||||
/>{' '}
|
||||
{t('settings.tts.filter.emojis', { defaultValue: '过滤表情符号' })}
|
||||
</FilterOptionItem>
|
||||
<FilterOptionItem>
|
||||
<LengthLabel>{t('settings.tts.max_text_length')}:</LengthLabel>
|
||||
<Select
|
||||
@ -969,7 +1010,8 @@ const TTSSettings: FC = () => {
|
||||
(ttsServiceType === 'openai' && (!ttsApiKey || !ttsVoice || !ttsModel)) ||
|
||||
(ttsServiceType === 'edge' && !ttsEdgeVoice) ||
|
||||
(ttsServiceType === 'siliconflow' &&
|
||||
(!ttsSiliconflowApiKey || !ttsSiliconflowVoice || !ttsSiliconflowModel))
|
||||
(!ttsSiliconflowApiKey || !ttsSiliconflowVoice || !ttsSiliconflowModel)) ||
|
||||
(ttsServiceType === 'mstts' && !ttsMsVoice)
|
||||
}>
|
||||
{t('settings.tts.test')}
|
||||
</Button>
|
||||
|
||||
@ -1,9 +1,10 @@
|
||||
import { InfoCircleOutlined, PhoneOutlined } from '@ant-design/icons'
|
||||
import { InfoCircleOutlined, PhoneOutlined, ReloadOutlined } from '@ant-design/icons'
|
||||
import SelectModelPopup from '@renderer/components/Popups/SelectModelPopup'
|
||||
import { getModelLogo } from '@renderer/config/models'
|
||||
import { DEFAULT_VOICE_CALL_PROMPT } from '@renderer/config/prompts'
|
||||
import { useAppDispatch } from '@renderer/store'
|
||||
import { setVoiceCallEnabled, setVoiceCallModel } from '@renderer/store/settings'
|
||||
import { Button, Form, Space, Switch, Tooltip as AntTooltip } from 'antd'
|
||||
import { setVoiceCallEnabled, setVoiceCallModel, setVoiceCallPrompt } from '@renderer/store/settings'
|
||||
import { Button, Form, Input, Space, Switch, Tooltip as AntTooltip } from 'antd'
|
||||
import { FC, useState } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { useSelector } from 'react-redux'
|
||||
@ -16,6 +17,10 @@ const VoiceCallSettings: FC = () => {
|
||||
// 从 Redux 获取通话功能设置
|
||||
const voiceCallEnabled = useSelector((state: any) => state.settings.voiceCallEnabled ?? true)
|
||||
const voiceCallModel = useSelector((state: any) => state.settings.voiceCallModel)
|
||||
const voiceCallPrompt = useSelector((state: any) => state.settings.voiceCallPrompt)
|
||||
|
||||
// 提示词编辑状态
|
||||
const [promptText, setPromptText] = useState<string>(voiceCallPrompt || DEFAULT_VOICE_CALL_PROMPT)
|
||||
|
||||
// 模型选择状态
|
||||
const [, setIsSelectingModel] = useState(false)
|
||||
@ -35,6 +40,19 @@ const VoiceCallSettings: FC = () => {
|
||||
}
|
||||
}
|
||||
|
||||
// 保存提示词
|
||||
const handleSavePrompt = () => {
|
||||
dispatch(setVoiceCallPrompt(promptText))
|
||||
window.message.success({ content: t('settings.voice_call.prompt.saved'), key: 'voice-call-prompt' })
|
||||
}
|
||||
|
||||
// 重置提示词
|
||||
const handleResetPrompt = () => {
|
||||
setPromptText(DEFAULT_VOICE_CALL_PROMPT)
|
||||
dispatch(setVoiceCallPrompt(null))
|
||||
window.message.success({ content: t('settings.voice_call.prompt.reset_done'), key: 'voice-call-prompt' })
|
||||
}
|
||||
|
||||
return (
|
||||
<Container>
|
||||
<Form layout="vertical">
|
||||
@ -71,6 +89,26 @@ const VoiceCallSettings: FC = () => {
|
||||
<InfoText>{t('settings.voice_call.model.info')}</InfoText>
|
||||
</Form.Item>
|
||||
|
||||
{/* 提示词设置 */}
|
||||
<Form.Item label={t('settings.voice_call.prompt.label')} style={{ marginBottom: 16 }}>
|
||||
<Input.TextArea
|
||||
value={promptText}
|
||||
onChange={(e) => setPromptText(e.target.value)}
|
||||
disabled={!voiceCallEnabled}
|
||||
rows={8}
|
||||
placeholder={t('settings.voice_call.prompt.placeholder')}
|
||||
/>
|
||||
<Space style={{ marginTop: 8 }}>
|
||||
<Button type="primary" onClick={handleSavePrompt} disabled={!voiceCallEnabled}>
|
||||
{t('settings.voice_call.prompt.save')}
|
||||
</Button>
|
||||
<Button onClick={handleResetPrompt} disabled={!voiceCallEnabled} icon={<ReloadOutlined />}>
|
||||
{t('settings.voice_call.prompt.reset')}
|
||||
</Button>
|
||||
</Space>
|
||||
<InfoText>{t('settings.voice_call.prompt.info')}</InfoText>
|
||||
</Form.Item>
|
||||
|
||||
{/* ASR 和 TTS 设置提示 */}
|
||||
<Form.Item>
|
||||
<Alert type="info">{t('settings.voice_call.asr_tts_info')}</Alert>
|
||||
|
||||
@ -14,13 +14,19 @@ class ASRServerService {
|
||||
startServer = async (): Promise<boolean> => {
|
||||
if (this.isServerRunning) {
|
||||
console.log('[ASRServerService] 服务器已经在运行中')
|
||||
window.message.info({ content: i18n.t('settings.asr.server.already_running'), key: 'asr-server' })
|
||||
// 安全地调用window.message
|
||||
if (window.message) {
|
||||
window.message.info({ content: i18n.t('settings.asr.server.already_running'), key: 'asr-server' })
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
try {
|
||||
console.log('[ASRServerService] 正在启动ASR服务器...')
|
||||
window.message.loading({ content: i18n.t('settings.asr.server.starting'), key: 'asr-server' })
|
||||
// 安全地调用window.message
|
||||
if (window.message) {
|
||||
window.message.loading({ content: i18n.t('settings.asr.server.starting'), key: 'asr-server' })
|
||||
}
|
||||
|
||||
// 使用IPC调用主进程启动服务器
|
||||
const result = await window.api.asrServer.startServer()
|
||||
@ -29,22 +35,28 @@ class ASRServerService {
|
||||
this.isServerRunning = true
|
||||
this.serverProcess = result.pid
|
||||
console.log('[ASRServerService] ASR服务器启动成功,PID:', result.pid)
|
||||
window.message.success({ content: i18n.t('settings.asr.server.started'), key: 'asr-server' })
|
||||
if (window.message) {
|
||||
window.message.success({ content: i18n.t('settings.asr.server.started'), key: 'asr-server' })
|
||||
}
|
||||
return true
|
||||
} else {
|
||||
console.error('[ASRServerService] ASR服务器启动失败:', result.error)
|
||||
window.message.error({
|
||||
content: i18n.t('settings.asr.server.start_failed') + ': ' + result.error,
|
||||
key: 'asr-server'
|
||||
})
|
||||
if (window.message) {
|
||||
window.message.error({
|
||||
content: i18n.t('settings.asr.server.start_failed') + ': ' + result.error,
|
||||
key: 'asr-server'
|
||||
})
|
||||
}
|
||||
return false
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('[ASRServerService] 启动ASR服务器时出错:', error)
|
||||
window.message.error({
|
||||
content: i18n.t('settings.asr.server.start_failed') + ': ' + (error as Error).message,
|
||||
key: 'asr-server'
|
||||
})
|
||||
if (window.message) {
|
||||
window.message.error({
|
||||
content: i18n.t('settings.asr.server.start_failed') + ': ' + (error as Error).message,
|
||||
key: 'asr-server'
|
||||
})
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
@ -56,13 +68,17 @@ class ASRServerService {
|
||||
stopServer = async (): Promise<boolean> => {
|
||||
if (!this.isServerRunning || !this.serverProcess) {
|
||||
console.log('[ASRServerService] 服务器未运行')
|
||||
window.message.info({ content: i18n.t('settings.asr.server.not_running'), key: 'asr-server' })
|
||||
if (window.message) {
|
||||
window.message.info({ content: i18n.t('settings.asr.server.not_running'), key: 'asr-server' })
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
try {
|
||||
console.log('[ASRServerService] 正在停止ASR服务器...')
|
||||
window.message.loading({ content: i18n.t('settings.asr.server.stopping'), key: 'asr-server' })
|
||||
if (window.message) {
|
||||
window.message.loading({ content: i18n.t('settings.asr.server.stopping'), key: 'asr-server' })
|
||||
}
|
||||
|
||||
// 使用IPC调用主进程停止服务器
|
||||
const result = await window.api.asrServer.stopServer(this.serverProcess)
|
||||
@ -71,22 +87,28 @@ class ASRServerService {
|
||||
this.isServerRunning = false
|
||||
this.serverProcess = null
|
||||
console.log('[ASRServerService] ASR服务器已停止')
|
||||
window.message.success({ content: i18n.t('settings.asr.server.stopped'), key: 'asr-server' })
|
||||
if (window.message) {
|
||||
window.message.success({ content: i18n.t('settings.asr.server.stopped'), key: 'asr-server' })
|
||||
}
|
||||
return true
|
||||
} else {
|
||||
console.error('[ASRServerService] ASR服务器停止失败:', result.error)
|
||||
window.message.error({
|
||||
content: i18n.t('settings.asr.server.stop_failed') + ': ' + result.error,
|
||||
key: 'asr-server'
|
||||
})
|
||||
if (window.message) {
|
||||
window.message.error({
|
||||
content: i18n.t('settings.asr.server.stop_failed') + ': ' + result.error,
|
||||
key: 'asr-server'
|
||||
})
|
||||
}
|
||||
return false
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('[ASRServerService] 停止ASR服务器时出错:', error)
|
||||
window.message.error({
|
||||
content: i18n.t('settings.asr.server.stop_failed') + ': ' + (error as Error).message,
|
||||
key: 'asr-server'
|
||||
})
|
||||
if (window.message) {
|
||||
window.message.error({
|
||||
content: i18n.t('settings.asr.server.stop_failed') + ': ' + (error as Error).message,
|
||||
key: 'asr-server'
|
||||
})
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
@ -104,7 +126,8 @@ class ASRServerService {
|
||||
* @returns string 网页URL
|
||||
*/
|
||||
getServerUrl = (): string => {
|
||||
return 'http://localhost:8080'
|
||||
console.log('[ASRServerService] 获取服务器URL: http://localhost:34515')
|
||||
return 'http://localhost:34515'
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -66,7 +66,7 @@ class ASRService {
|
||||
console.log('[ASRService] 正在连接WebSocket服务器...')
|
||||
window.message.loading({ content: '正在连接语音识别服务...', key: 'ws-connect' })
|
||||
|
||||
this.ws = new WebSocket('ws://localhost:8080')
|
||||
this.ws = new WebSocket('ws://localhost:34515') // 使用正确的端口 34515
|
||||
this.wsConnected = false
|
||||
this.browserReady = false
|
||||
|
||||
@ -253,6 +253,9 @@ class ASRService {
|
||||
throw new Error('无法连接到语音识别服务')
|
||||
}
|
||||
|
||||
// 获取语言设置
|
||||
const { asrLanguage } = store.getState().settings
|
||||
|
||||
// 检查浏览器是否准备好
|
||||
if (!this.browserReady) {
|
||||
// 尝试等待浏览器准备好
|
||||
@ -270,7 +273,7 @@ class ASRService {
|
||||
// 尝试自动打开浏览器页面
|
||||
try {
|
||||
// 使用ASRServerService获取服务器URL
|
||||
const serverUrl = 'http://localhost:8080'
|
||||
const serverUrl = 'http://localhost:34515' // 使用正确的端口 34515
|
||||
console.log('尝试打开语音识别服务器页面:', serverUrl)
|
||||
window.open(serverUrl, '_blank')
|
||||
} catch (error) {
|
||||
@ -302,9 +305,15 @@ class ASRService {
|
||||
|
||||
// 发送开始命令
|
||||
if (this.ws && this.wsConnected) {
|
||||
this.ws.send(JSON.stringify({ type: 'start' }))
|
||||
// 将语言设置传递给服务器
|
||||
this.ws.send(
|
||||
JSON.stringify({
|
||||
type: 'start',
|
||||
language: asrLanguage || 'zh-CN' // 使用设置的语言或默认中文
|
||||
})
|
||||
)
|
||||
this.isRecording = true
|
||||
console.log('开始语音识别')
|
||||
console.log('开始语音识别,语言:', asrLanguage || 'zh-CN')
|
||||
window.message.info({ content: i18n.t('settings.asr.recording'), key: 'asr-recording' })
|
||||
} else {
|
||||
throw new Error('WebSocket连接未就绪')
|
||||
@ -638,7 +647,7 @@ class ASRService {
|
||||
*/
|
||||
openBrowserPage = (): void => {
|
||||
// 使用window.open打开浏览器页面
|
||||
window.open('http://localhost:8080', '_blank')
|
||||
window.open('http://localhost:34515', '_blank') // 使用正确的端口 34515
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
import { DEFAULT_VOICE_CALL_PROMPT } from '@renderer/config/prompts'
|
||||
import { fetchChatCompletion } from '@renderer/services/ApiService'
|
||||
import ASRService from '@renderer/services/ASRService'
|
||||
import { getDefaultAssistant } from '@renderer/services/AssistantService'
|
||||
@ -5,8 +6,10 @@ import { EVENT_NAMES, EventEmitter } from '@renderer/services/EventService'
|
||||
import { getAssistantMessage, getUserMessage } from '@renderer/services/MessagesService'
|
||||
import TTSService from '@renderer/services/TTSService'
|
||||
import store from '@renderer/store'
|
||||
import { setSkipNextAutoTTS } from '@renderer/store/settings'
|
||||
// 导入类型
|
||||
import type { Message } from '@renderer/types'
|
||||
import i18n from 'i18next'
|
||||
|
||||
interface VoiceCallCallbacks {
|
||||
onTranscript: (text: string) => void
|
||||
@ -170,9 +173,13 @@ class VoiceCallServiceClass {
|
||||
}
|
||||
}
|
||||
|
||||
// 播放欢迎语音
|
||||
const welcomeMessage = '您好,我是您的AI助手,请长按说话按钮进行对话。'
|
||||
this.callbacks?.onResponse(welcomeMessage)
|
||||
// 设置skipNextAutoTTS为true,防止自动播放最后一条消息
|
||||
store.dispatch(setSkipNextAutoTTS(true))
|
||||
|
||||
// 播放欢迎语音 - 根据当前语言获取本地化的欢迎消息
|
||||
const welcomeMessage = i18n.t('settings.voice_call.welcome_message')
|
||||
// 不调用onResponse,避免触发两次TTS播放
|
||||
// this.callbacks?.onResponse(welcomeMessage)
|
||||
|
||||
// 监听TTS状态
|
||||
const ttsStateHandler = (isPlaying: boolean) => {
|
||||
@ -583,21 +590,16 @@ class VoiceCallServiceClass {
|
||||
}
|
||||
})
|
||||
|
||||
// 修改用户消息,添加语音通话提示
|
||||
const voiceCallPrompt = `当前是语音通话模式。请注意:
|
||||
1. 简洁直接地回答问题,避免冗长的引导和总结。
|
||||
2. 避免使用复杂的格式化内容,如表格、代码块、Markdown等。
|
||||
3. 使用自然、口语化的表达方式,就像与人对话一样。
|
||||
4. 如果需要列出要点,使用简单的数字或文字标记,而不是复杂的格式。
|
||||
5. 回答应该简短有力,便于用户通过语音理解。
|
||||
6. 避免使用特殊符号、表情符号、标点符号等,因为这些在语音播放时会影响理解。
|
||||
7. 使用完整的句子而非简单的关键词列表。
|
||||
8. 尽量使用常见词汇,避免生僻或专业术语,除非用户特别询问。`
|
||||
// 获取用户自定义提示词
|
||||
const { voiceCallPrompt } = store.getState().settings
|
||||
|
||||
// 使用自定义提示词或默认提示词
|
||||
const promptToUse = voiceCallPrompt || DEFAULT_VOICE_CALL_PROMPT
|
||||
|
||||
// 创建系统指令消息
|
||||
const systemMessage = {
|
||||
role: 'system',
|
||||
content: voiceCallPrompt
|
||||
content: promptToUse
|
||||
}
|
||||
|
||||
// 修改用户消息的内容
|
||||
@ -646,8 +648,12 @@ class VoiceCallServiceClass {
|
||||
// 添加事件监听器
|
||||
window.addEventListener('tts-state-change', handleTTSStateChange as EventListener)
|
||||
|
||||
// 开始播放
|
||||
this.ttsService.speak(fullResponse)
|
||||
// 更新助手消息的内容
|
||||
assistantMessage.content = fullResponse
|
||||
assistantMessage.status = 'success'
|
||||
|
||||
// 使用speakFromMessage方法播放,会应用TTS过滤选项
|
||||
this.ttsService.speakFromMessage(assistantMessage)
|
||||
|
||||
// 设置超时安全机制,确保事件监听器被移除
|
||||
setTimeout(() => {
|
||||
@ -666,7 +672,17 @@ class VoiceCallServiceClass {
|
||||
if (!this.isMuted && this.isCallActive) {
|
||||
// 手动设置语音状态
|
||||
this.callbacks?.onSpeakingStateChange(true)
|
||||
this.ttsService.speak(fullResponse)
|
||||
|
||||
// 创建一个简单的助手消息对象
|
||||
const errorMessage = {
|
||||
id: 'error-message',
|
||||
role: 'assistant',
|
||||
content: fullResponse,
|
||||
status: 'success'
|
||||
} as Message
|
||||
|
||||
// 使用speakFromMessage方法播放,会应用TTS过滤选项
|
||||
this.ttsService.speakFromMessage(errorMessage)
|
||||
|
||||
// 确保语音结束后状态正确
|
||||
setTimeout(() => {
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
import i18n from '@renderer/i18n'
|
||||
|
||||
import { TTSServiceInterface } from './TTSServiceInterface'
|
||||
|
||||
/**
|
||||
@ -27,7 +25,15 @@ export class MsTTSService implements TTSServiceInterface {
|
||||
*/
|
||||
private validateParams(): void {
|
||||
if (!this.voice) {
|
||||
throw new Error(i18n.t('settings.tts.error.no_mstts_voice'))
|
||||
// 如果没有设置音色,使用默认的小晓音色
|
||||
console.warn('未设置免费在线TTS音色,使用默认音色 zh-CN-XiaoxiaoNeural')
|
||||
this.voice = 'zh-CN-XiaoxiaoNeural'
|
||||
}
|
||||
|
||||
if (!this.outputFormat) {
|
||||
// 如果没有设置输出格式,使用默认格式
|
||||
console.warn('未设置免费在线TTS输出格式,使用默认格式 audio-24khz-48kbitrate-mono-mp3')
|
||||
this.outputFormat = 'audio-24khz-48kbitrate-mono-mp3'
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -104,6 +104,7 @@ export class TTSService {
|
||||
filterMarkdown: true,
|
||||
filterCodeBlocks: true,
|
||||
filterHtmlTags: true,
|
||||
filterEmojis: true,
|
||||
maxTextLength: 4000
|
||||
}
|
||||
|
||||
@ -592,7 +593,7 @@ export class TTSService {
|
||||
// 触发进度更新事件
|
||||
this.emitProgressUpdateEvent(currentTime, duration, progress)
|
||||
}
|
||||
}, 100)
|
||||
}, 250) // 将更新频率从100ms降低到250ms,减少日志输出
|
||||
}
|
||||
|
||||
/**
|
||||
@ -611,6 +612,11 @@ export class TTSService {
|
||||
* @param duration 总时长(秒)
|
||||
* @param progress 进度百分比(0-100)
|
||||
*/
|
||||
// 记录上次输出日志的进度百分比 - 已禁用日志输出
|
||||
// private lastLoggedProgress: number = -1;
|
||||
// 记录上次日志输出时间,用于节流 - 已禁用日志输出
|
||||
// private lastLogTime: number = 0;
|
||||
|
||||
private emitProgressUpdateEvent(currentTime: number, duration: number, progress: number): void {
|
||||
// 创建事件数据
|
||||
const eventData = {
|
||||
@ -621,12 +627,21 @@ export class TTSService {
|
||||
progress
|
||||
}
|
||||
|
||||
console.log('发送TTS进度更新事件:', {
|
||||
messageId: this.playingMessageId,
|
||||
progress: Math.round(progress),
|
||||
currentTime: Math.round(currentTime),
|
||||
duration: Math.round(duration)
|
||||
})
|
||||
// 完全关闭进度更新日志输出
|
||||
// const now = Date.now();
|
||||
// const currentProgressTens = Math.floor(progress / 10);
|
||||
// if ((now - this.lastLogTime >= 500) && // 时间节流
|
||||
// (currentProgressTens !== Math.floor(this.lastLoggedProgress / 10) ||
|
||||
// progress === 0 || progress >= 100)) {
|
||||
// console.log('发送TTS进度更新事件:', {
|
||||
// messageId: this.playingMessageId ? this.playingMessageId.substring(0, 8) : null,
|
||||
// progress: Math.round(progress),
|
||||
// currentTime: Math.round(currentTime),
|
||||
// duration: Math.round(duration)
|
||||
// });
|
||||
// this.lastLoggedProgress = progress;
|
||||
// this.lastLogTime = now;
|
||||
// }
|
||||
|
||||
// 触发事件
|
||||
window.dispatchEvent(new CustomEvent('tts-progress-update', { detail: eventData }))
|
||||
|
||||
@ -48,14 +48,17 @@ export class TTSServiceFactory {
|
||||
settings.ttsSiliconflowSpeed
|
||||
)
|
||||
|
||||
case 'mstts':
|
||||
case 'mstts': {
|
||||
console.log('创建免费在线TTS服务实例')
|
||||
// 确保音色有默认值
|
||||
const msVoice = settings.ttsMsVoice || 'zh-CN-XiaoxiaoNeural'
|
||||
const msOutputFormat = settings.ttsMsOutputFormat || 'audio-24khz-48kbitrate-mono-mp3'
|
||||
console.log('免费在线TTS设置:', {
|
||||
voice: settings.ttsMsVoice,
|
||||
outputFormat: settings.ttsMsOutputFormat
|
||||
voice: msVoice,
|
||||
outputFormat: msOutputFormat
|
||||
})
|
||||
return new MsTTSService(settings.ttsMsVoice, settings.ttsMsOutputFormat)
|
||||
|
||||
return new MsTTSService(msVoice, msOutputFormat)
|
||||
} // Close block scope
|
||||
default:
|
||||
throw new Error(i18n.t('settings.tts.error.unsupported_service_type', { serviceType }))
|
||||
}
|
||||
|
||||
@ -16,6 +16,7 @@ export class TTSTextFilter {
|
||||
filterMarkdown: boolean
|
||||
filterCodeBlocks: boolean
|
||||
filterHtmlTags: boolean
|
||||
filterEmojis: boolean
|
||||
maxTextLength: number
|
||||
}
|
||||
): string {
|
||||
@ -43,6 +44,11 @@ export class TTSTextFilter {
|
||||
filteredText = this.filterHtmlTags(filteredText)
|
||||
}
|
||||
|
||||
// 过滤表情符号
|
||||
if (options.filterEmojis) {
|
||||
filteredText = this.filterEmojis(filteredText)
|
||||
}
|
||||
|
||||
// 限制文本长度
|
||||
if (options.maxTextLength > 0 && filteredText.length > options.maxTextLength) {
|
||||
filteredText = filteredText.substring(0, options.maxTextLength)
|
||||
@ -145,4 +151,18 @@ export class TTSTextFilter {
|
||||
|
||||
return text
|
||||
}
|
||||
|
||||
/**
|
||||
* 过滤表情符号
|
||||
* @param text 原始文本
|
||||
* @returns 过滤后的文本
|
||||
*/
|
||||
private static filterEmojis(text: string): string {
|
||||
// 过滤Unicode表情符号
|
||||
// 这个正则表达式匹配大多数常见的表情符号
|
||||
return text.replace(
|
||||
/[\u{1F300}-\u{1F5FF}\u{1F600}-\u{1F64F}\u{1F680}-\u{1F6FF}\u{1F700}-\u{1F77F}\u{1F780}-\u{1F7FF}\u{1F800}-\u{1F8FF}\u{1F900}-\u{1F9FF}\u{1FA00}-\u{1FA6F}\u{1FA70}-\u{1FAFF}\u{2600}-\u{26FF}\u{2700}-\u{27BF}]/gu,
|
||||
''
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@ -119,6 +119,7 @@ export interface SettingsState {
|
||||
ttsModel: string
|
||||
ttsCustomVoices: string[]
|
||||
ttsCustomModels: string[]
|
||||
showTTSProgressBar: boolean // 是否显示TTS进度条
|
||||
// 浏览器 TTS配置
|
||||
ttsEdgeVoice: string
|
||||
// 硅基流动 TTS配置
|
||||
@ -137,6 +138,7 @@ export interface SettingsState {
|
||||
filterMarkdown: boolean // 过滤Markdown标记
|
||||
filterCodeBlocks: boolean // 过滤代码块
|
||||
filterHtmlTags: boolean // 过滤HTML标签
|
||||
filterEmojis: boolean // 过滤表情符号
|
||||
maxTextLength: number // 最大文本长度
|
||||
}
|
||||
// ASR配置(语音识别)
|
||||
@ -146,9 +148,11 @@ export interface SettingsState {
|
||||
asrApiUrl: string
|
||||
asrModel: string
|
||||
asrAutoStartServer: boolean // 启动应用时自动启动ASR服务器
|
||||
asrLanguage: string // 语音识别语言
|
||||
// 语音通话配置
|
||||
voiceCallEnabled: boolean
|
||||
voiceCallModel: Model | null
|
||||
voiceCallPrompt: string | null // 语音通话自定义提示词
|
||||
isVoiceCallActive: boolean // 语音通话窗口是否激活
|
||||
lastPlayedMessageId: string | null // 最后一次播放的消息ID
|
||||
skipNextAutoTTS: boolean // 是否跳过下一次自动TTS
|
||||
@ -262,6 +266,7 @@ export const initialState: SettingsState = {
|
||||
ttsModel: '',
|
||||
ttsCustomVoices: [],
|
||||
ttsCustomModels: [],
|
||||
showTTSProgressBar: true, // 默认显示TTS进度条
|
||||
// Edge TTS配置
|
||||
ttsEdgeVoice: 'zh-CN-XiaoxiaoNeural', // 默认使用小小的声音
|
||||
// 硅基流动 TTS配置
|
||||
@ -279,6 +284,7 @@ export const initialState: SettingsState = {
|
||||
filterMarkdown: true, // 默认过滤Markdown标记
|
||||
filterCodeBlocks: true, // 默认过滤代码块
|
||||
filterHtmlTags: true, // 默认过滤HTML标签
|
||||
filterEmojis: true, // 默认过滤表情符号
|
||||
maxTextLength: 4000 // 默认最大文本长度
|
||||
},
|
||||
// ASR配置(语音识别)
|
||||
@ -288,9 +294,11 @@ export const initialState: SettingsState = {
|
||||
asrApiUrl: 'https://api.openai.com/v1/audio/transcriptions',
|
||||
asrModel: 'whisper-1',
|
||||
asrAutoStartServer: false, // 默认不自动启动ASR服务器
|
||||
asrLanguage: 'zh-CN', // 默认使用中文
|
||||
// 语音通话配置
|
||||
voiceCallEnabled: true,
|
||||
voiceCallModel: null,
|
||||
voiceCallPrompt: null, // 默认为null,表示使用默认提示词
|
||||
isVoiceCallActive: false, // 语音通话窗口是否激活
|
||||
lastPlayedMessageId: null, // 最后一次播放的消息ID
|
||||
skipNextAutoTTS: false, // 是否跳过下一次自动TTS
|
||||
@ -692,6 +700,7 @@ const settingsSlice = createSlice({
|
||||
filterMarkdown?: boolean
|
||||
filterCodeBlocks?: boolean
|
||||
filterHtmlTags?: boolean
|
||||
filterEmojis?: boolean
|
||||
maxTextLength?: number
|
||||
}>
|
||||
) => {
|
||||
@ -700,6 +709,10 @@ const settingsSlice = createSlice({
|
||||
...action.payload
|
||||
}
|
||||
},
|
||||
// 设置是否显示TTS进度条
|
||||
setShowTTSProgressBar: (state, action: PayloadAction<boolean>) => {
|
||||
state.showTTSProgressBar = action.payload
|
||||
},
|
||||
// ASR相关的action
|
||||
setAsrEnabled: (state, action: PayloadAction<boolean>) => {
|
||||
state.asrEnabled = action.payload
|
||||
@ -719,12 +732,18 @@ const settingsSlice = createSlice({
|
||||
setAsrAutoStartServer: (state, action: PayloadAction<boolean>) => {
|
||||
state.asrAutoStartServer = action.payload
|
||||
},
|
||||
setAsrLanguage: (state, action: PayloadAction<string>) => {
|
||||
state.asrLanguage = action.payload
|
||||
},
|
||||
setVoiceCallEnabled: (state, action: PayloadAction<boolean>) => {
|
||||
state.voiceCallEnabled = action.payload
|
||||
},
|
||||
setVoiceCallModel: (state, action: PayloadAction<Model | null>) => {
|
||||
state.voiceCallModel = action.payload
|
||||
},
|
||||
setVoiceCallPrompt: (state, action: PayloadAction<string | null>) => {
|
||||
state.voiceCallPrompt = action.payload
|
||||
},
|
||||
setIsVoiceCallActive: (state, action: PayloadAction<boolean>) => {
|
||||
state.isVoiceCallActive = action.payload
|
||||
},
|
||||
@ -851,14 +870,17 @@ export const {
|
||||
removeTtsCustomVoice,
|
||||
removeTtsCustomModel,
|
||||
setTtsFilterOptions,
|
||||
setShowTTSProgressBar,
|
||||
setAsrEnabled,
|
||||
setAsrServiceType,
|
||||
setAsrApiKey,
|
||||
setAsrApiUrl,
|
||||
setAsrModel,
|
||||
setAsrAutoStartServer,
|
||||
setAsrLanguage,
|
||||
setVoiceCallEnabled,
|
||||
setVoiceCallModel,
|
||||
setVoiceCallPrompt,
|
||||
setIsVoiceCallActive,
|
||||
setLastPlayedMessageId,
|
||||
setSkipNextAutoTTS
|
||||
|
||||
36
yarn.lock
36
yarn.lock
@ -3945,6 +3945,7 @@ __metadata:
|
||||
axios: "npm:^1.7.3"
|
||||
babel-plugin-styled-components: "npm:^2.1.4"
|
||||
browser-image-compression: "npm:^2.0.2"
|
||||
bufferutil: "npm:^4.0.9"
|
||||
color: "npm:^5.0.0"
|
||||
dayjs: "npm:^1.11.11"
|
||||
dexie: "npm:^4.0.8"
|
||||
@ -4021,9 +4022,11 @@ __metadata:
|
||||
turndown-plugin-gfm: "npm:^1.0.2"
|
||||
typescript: "npm:^5.6.2"
|
||||
undici: "npm:^7.4.0"
|
||||
utf-8-validate: "npm:^6.0.5"
|
||||
uuid: "npm:^10.0.0"
|
||||
vite: "npm:^5.0.12"
|
||||
webdav: "npm:^5.8.0"
|
||||
ws: "npm:^8.18.1"
|
||||
zipread: "npm:^1.3.3"
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
@ -4938,6 +4941,16 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"bufferutil@npm:^4.0.9":
|
||||
version: 4.0.9
|
||||
resolution: "bufferutil@npm:4.0.9"
|
||||
dependencies:
|
||||
node-gyp: "npm:latest"
|
||||
node-gyp-build: "npm:^4.3.0"
|
||||
checksum: 10c0/f8a93279fc9bdcf32b42eba97edc672b39ca0fe5c55a8596099886cffc76ea9dd78e0f6f51ecee3b5ee06d2d564aa587036b5d4ea39b8b5ac797262a363cdf7d
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"builder-util-runtime@npm:9.2.4":
|
||||
version: 9.2.4
|
||||
resolution: "builder-util-runtime@npm:9.2.4"
|
||||
@ -12107,6 +12120,17 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"node-gyp-build@npm:^4.3.0":
|
||||
version: 4.8.4
|
||||
resolution: "node-gyp-build@npm:4.8.4"
|
||||
bin:
|
||||
node-gyp-build: bin.js
|
||||
node-gyp-build-optional: optional.js
|
||||
node-gyp-build-test: build-test.js
|
||||
checksum: 10c0/444e189907ece2081fe60e75368784f7782cfddb554b60123743dfb89509df89f1f29c03bbfa16b3a3e0be3f48799a4783f487da6203245fa5bed239ba7407e1
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"node-gyp@npm:^9.1.0":
|
||||
version: 9.4.1
|
||||
resolution: "node-gyp@npm:9.4.1"
|
||||
@ -16635,6 +16659,16 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"utf-8-validate@npm:^6.0.5":
|
||||
version: 6.0.5
|
||||
resolution: "utf-8-validate@npm:6.0.5"
|
||||
dependencies:
|
||||
node-gyp: "npm:latest"
|
||||
node-gyp-build: "npm:^4.3.0"
|
||||
checksum: 10c0/6dc63c513adb001e47a51819072cdd414158430091c49c21d4947ea99f16df5167b671f680df8fb2b6f2ae6a7f30264b4ec111bd3e573720dfe371da1ab99a81
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"utf8-byte-length@npm:^1.0.1":
|
||||
version: 1.0.5
|
||||
resolution: "utf8-byte-length@npm:1.0.5"
|
||||
@ -17069,7 +17103,7 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"ws@npm:^8.13.0, ws@npm:^8.14.1, ws@npm:^8.18.0":
|
||||
"ws@npm:^8.13.0, ws@npm:^8.14.1, ws@npm:^8.18.0, ws@npm:^8.18.1":
|
||||
version: 8.18.1
|
||||
resolution: "ws@npm:8.18.1"
|
||||
peerDependencies:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user