update server.js
Browse files- server.js +12 -0
- src/hooks/useVoiceSession.ts +6 -2
- src/services/voiceApi.ts +9 -3
server.js
CHANGED
|
@@ -77,6 +77,18 @@ const server = http.createServer((req, res) => {
|
|
| 77 |
return;
|
| 78 |
}
|
| 79 |
const ext = path.extname(filePath).toLowerCase();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
res.writeHead(200, { "Content-Type": MIME[ext] || "application/octet-stream" });
|
| 81 |
res.end(data);
|
| 82 |
});
|
|
|
|
| 77 |
return;
|
| 78 |
}
|
| 79 |
const ext = path.extname(filePath).toLowerCase();
|
| 80 |
+
|
| 81 |
+
if (ext === ".html") {
|
| 82 |
+
const config = { VOICE_API_URL: process.env.VITE_API_BASE_VOICE_URL || "" };
|
| 83 |
+
const html = data.toString().replace(
|
| 84 |
+
"</head>",
|
| 85 |
+
`<script>window.__APP_CONFIG__=${JSON.stringify(config)};</script></head>`
|
| 86 |
+
);
|
| 87 |
+
res.writeHead(200, { "Content-Type": "text/html" });
|
| 88 |
+
res.end(html);
|
| 89 |
+
return;
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
res.writeHead(200, { "Content-Type": MIME[ext] || "application/octet-stream" });
|
| 93 |
res.end(data);
|
| 94 |
});
|
src/hooks/useVoiceSession.ts
CHANGED
|
@@ -40,8 +40,12 @@ const BUFFER_SOUNDS = [
|
|
| 40 |
const RECORDER_SAMPLE_RATE = 16000;
|
| 41 |
|
| 42 |
function getVoiceHttpBaseUrl(): string {
|
| 43 |
-
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
}
|
| 46 |
|
| 47 |
export function useVoiceSession(opts: UseVoiceSessionOptions): UseVoiceSessionReturn {
|
|
|
|
| 40 |
const RECORDER_SAMPLE_RATE = 16000;
|
| 41 |
|
| 42 |
function getVoiceHttpBaseUrl(): string {
|
| 43 |
+
const w = window as unknown as { __APP_CONFIG__?: { VOICE_API_URL?: string } };
|
| 44 |
+
return (
|
| 45 |
+
w.__APP_CONFIG__?.VOICE_API_URL ||
|
| 46 |
+
(import.meta as unknown as { env: Record<string, string> }).env.VITE_API_BASE_VOICE_URL ||
|
| 47 |
+
"http://localhost:7861"
|
| 48 |
+
);
|
| 49 |
}
|
| 50 |
|
| 51 |
export function useVoiceSession(opts: UseVoiceSessionOptions): UseVoiceSessionReturn {
|
src/services/voiceApi.ts
CHANGED
|
@@ -1,6 +1,12 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
function writeString(view: DataView, offset: number, str: string): void {
|
| 6 |
for (let i = 0; i < str.length; i++) view.setUint8(offset + i, str.charCodeAt(i));
|
|
|
|
| 1 |
+
function getVoiceBaseUrl(): string {
|
| 2 |
+
const w = window as unknown as { __APP_CONFIG__?: { VOICE_API_URL?: string } };
|
| 3 |
+
return (
|
| 4 |
+
w.__APP_CONFIG__?.VOICE_API_URL ||
|
| 5 |
+
(import.meta as unknown as { env: Record<string, string> }).env.VITE_API_BASE_VOICE_URL ||
|
| 6 |
+
"http://localhost:7861"
|
| 7 |
+
);
|
| 8 |
+
}
|
| 9 |
+
const VOICE_BASE_URL = getVoiceBaseUrl();
|
| 10 |
|
| 11 |
function writeString(view: DataView, offset: number, str: string): void {
|
| 12 |
for (let i = 0; i < str.length; i++) view.setUint8(offset + i, str.charCodeAt(i));
|