mirror of
https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
synced 2025-10-03 00:26:40 +08:00
commit
82af6ed98c
@ -101,9 +101,7 @@ export default function VoiceInput({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const startRecognition = async () => {
|
const startRecognition = () => {
|
||||||
let token = await get_access_token();
|
|
||||||
|
|
||||||
if (voiceInputLoading) {
|
if (voiceInputLoading) {
|
||||||
recognizer.current?.close();
|
recognizer.current?.close();
|
||||||
setVoiceInputLoading(false);
|
setVoiceInputLoading(false);
|
||||||
@ -116,37 +114,42 @@ export default function VoiceInput({
|
|||||||
setTempUserInput(userInput); // 开始的时候拷贝一份用于复原
|
setTempUserInput(userInput); // 开始的时候拷贝一份用于复原
|
||||||
setVoiceInputText("");
|
setVoiceInputText("");
|
||||||
|
|
||||||
const speechConfig = ms_audio_sdk.SpeechConfig.fromAuthorizationToken(
|
const getToken = async () => {
|
||||||
token,
|
return await get_access_token();
|
||||||
"eastasia",
|
};
|
||||||
);
|
getToken().then((token) => {
|
||||||
const audioConfig = ms_audio_sdk.AudioConfig.fromDefaultMicrophoneInput();
|
const speechConfig = ms_audio_sdk.SpeechConfig.fromAuthorizationToken(
|
||||||
speechConfig.speechRecognitionLanguage = "zh-CN";
|
token,
|
||||||
speechConfig.setProperty(
|
"eastasia",
|
||||||
ms_audio_sdk.PropertyId.SpeechServiceConnection_EndSilenceTimeoutMs,
|
);
|
||||||
"3500",
|
const audioConfig = ms_audio_sdk.AudioConfig.fromDefaultMicrophoneInput();
|
||||||
);
|
speechConfig.speechRecognitionLanguage = "zh-CN";
|
||||||
recognizer.current = new ms_audio_sdk.SpeechRecognizer(
|
speechConfig.setProperty(
|
||||||
speechConfig,
|
ms_audio_sdk.PropertyId.SpeechServiceConnection_EndSilenceTimeoutMs,
|
||||||
audioConfig,
|
"3500",
|
||||||
);
|
);
|
||||||
recognizer.current.recognizing = onRecognizing; // 自定义分段显示
|
recognizer.current = new ms_audio_sdk.SpeechRecognizer(
|
||||||
recognizer.current.canceled = onCanceled; // 自定义中断
|
speechConfig,
|
||||||
recognizer.current.recognizeOnceAsync(
|
audioConfig,
|
||||||
(result) => {
|
);
|
||||||
onRecognizedResult(result);
|
recognizer.current.recognizing = onRecognizing; // 自定义分段显示
|
||||||
setUserInput(
|
recognizer.current.canceled = onCanceled; // 自定义中断
|
||||||
tempUserInput + (voiceInputText ?? "") + `${result.text ?? ""}`,
|
recognizer.current.recognizeOnceAsync(
|
||||||
);
|
(result) => {
|
||||||
setTempUserInput("");
|
onRecognizedResult(result);
|
||||||
setVoiceInputText("");
|
setUserInput(
|
||||||
setVoiceInputLoading(false);
|
tempUserInput + (voiceInputText ?? "") + `${result.text ?? ""}`,
|
||||||
},
|
);
|
||||||
(err) => {
|
setTempUserInput("");
|
||||||
console.error("Recognition error: ", err); // 错误处理
|
setVoiceInputText("");
|
||||||
setVoiceInputLoading(false);
|
setVoiceInputLoading(false);
|
||||||
},
|
},
|
||||||
);
|
(err) => {
|
||||||
|
console.error("Recognition error: ", err); // 错误处理
|
||||||
|
setVoiceInputLoading(false);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const icon = useMemo(() => {
|
const icon = useMemo(() => {
|
||||||
|
72
lib/utils.ts
72
lib/utils.ts
@ -8,18 +8,18 @@ export function getTokenLength(input: string): number {
|
|||||||
return encoding.encode(input).length;
|
return encoding.encode(input).length;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function fetcher<JSON = any>(
|
// export async function fetcher<JSON = any>(
|
||||||
input: RequestInfo,
|
// input: RequestInfo,
|
||||||
init?: RequestInit,
|
// init?: RequestInit,
|
||||||
): Promise<JSON> {
|
// ): Promise<JSON> {
|
||||||
const response = await fetch(input, { ...init, cache: "no-store" });
|
// const response = await fetch(input, { ...init, cache: "no-store" });
|
||||||
|
//
|
||||||
|
// return response.json();
|
||||||
|
// }
|
||||||
|
|
||||||
return response.json();
|
// export const capitalize = (s: string) => {
|
||||||
}
|
// return s.charAt(0).toUpperCase() + s.slice(1);
|
||||||
|
// };
|
||||||
export const capitalize = (s: string) => {
|
|
||||||
return s.charAt(0).toUpperCase() + s.slice(1);
|
|
||||||
};
|
|
||||||
|
|
||||||
export const truncate = (str: string, num: number) => {
|
export const truncate = (str: string, num: number) => {
|
||||||
if (!str) return "";
|
if (!str) return "";
|
||||||
@ -29,33 +29,33 @@ export const truncate = (str: string, num: number) => {
|
|||||||
return str.slice(0, num) + "...";
|
return str.slice(0, num) + "...";
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getBlurDataURL = async (url: string | null) => {
|
// export const getBlurDataURL = async (url: string | null) => {
|
||||||
if (!url) {
|
// if (!url) {
|
||||||
return "data:image/webp;base64,AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";
|
// return "data:image/webp;base64,AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";
|
||||||
}
|
// }
|
||||||
try {
|
// try {
|
||||||
const response = await fetch(
|
// const response = await fetch(
|
||||||
`https://wsrv.nl/?url=${url}&w=50&h=50&blur=5`,
|
// `https://wsrv.nl/?url=${url}&w=50&h=50&blur=5`,
|
||||||
);
|
// );
|
||||||
const buffer = await response.arrayBuffer();
|
// const buffer = await response.arrayBuffer();
|
||||||
const base64 = Buffer.from(buffer).toString("base64");
|
// const base64 = Buffer.from(buffer).toString("base64");
|
||||||
|
//
|
||||||
|
// return `data:image/png;base64,${base64}`;
|
||||||
|
// } catch (error) {
|
||||||
|
// return "data:image/webp;base64,AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";
|
||||||
|
// }
|
||||||
|
// };
|
||||||
|
|
||||||
return `data:image/png;base64,${base64}`;
|
// export const placeholderBlurhash =
|
||||||
} catch (error) {
|
// "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAAXNSR0IArs4c6QAAAoJJREFUWEfFl4lu4zAMRO3cx/9/au6reMaOdkxTTl0grQFCRoqaT+SQotq2bV9N8rRt28xms87m83l553eZ/9vr9Wpkz+ezkT0ej+6dv1X81AFw7M4FBACPVn2c1Z3zLgDeJwHgeLFYdAARYioAEAKJEG2WAjl3gCwNYymQQ9b7/V4spmIAwO6Wy2VnAMikBWlDURBELf8CuN1uHQSrPwMAHK5WqwFELQ01AIXdAa7XawfAb3p6AOwK5+v1ugAoEq4FRSFLgavfQ49jAGQpAE5wjgGCeRrGdBArwHOPcwFcLpcGU1X0IsBuN5tNgYhaiFFwHTiAwq8I+O5xfj6fOz38K+X/fYAdb7fbAgFAjIJ6Aav3AYlQ6nfnDoDz0+lUxNiLALvf7XaDNGQ6GANQBKR85V27B4D3QQRw7hGIYlQKWGM79hSweyCUe1blXhEAogfABwHAXAcqSYkxCtHLUK3XBajSc4Dj8dilAeiSAgD2+30BAEKV4GKcAuDqB4TdYwBgPQByCgApUBoE4EJUGvxUjF3Q69/zLw3g/HA45ABKgdIQu+JPIyDnisCfAxAFNFM0EFNQ64gfS0EUoQP8ighrZSjn3oziZEQpauyKbfjbZchHUL/3AS/Dd30gAkxuRACgfO+EWQW8qwI1o+wseNuKcQiESjALvwNoMI0TcRzD4lFcPYwIM+JTF5x6HOs8yI7jeB5oKhpMRFH9UwaSCDB2Jmg4rc6E2TT0biIaG0rQhNqyhpHBcayTTSXH6vcDL7/sdqRK8LkwTsU499E8vRcAojHcZ4AxABdilgrp4lsXk8oVqgwh7+6H3phqd8J0Kk4vbx/+sZqCD/vNLya/5dT9fAH8g1WdNGgwbQAAAABJRU5ErkJggg==";
|
||||||
return "data:image/webp;base64,AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export const placeholderBlurhash =
|
// export const toDateString = (date: Date) => {
|
||||||
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAAXNSR0IArs4c6QAAAoJJREFUWEfFl4lu4zAMRO3cx/9/au6reMaOdkxTTl0grQFCRoqaT+SQotq2bV9N8rRt28xms87m83l553eZ/9vr9Wpkz+ezkT0ej+6dv1X81AFw7M4FBACPVn2c1Z3zLgDeJwHgeLFYdAARYioAEAKJEG2WAjl3gCwNYymQQ9b7/V4spmIAwO6Wy2VnAMikBWlDURBELf8CuN1uHQSrPwMAHK5WqwFELQ01AIXdAa7XawfAb3p6AOwK5+v1ugAoEq4FRSFLgavfQ49jAGQpAE5wjgGCeRrGdBArwHOPcwFcLpcGU1X0IsBuN5tNgYhaiFFwHTiAwq8I+O5xfj6fOz38K+X/fYAdb7fbAgFAjIJ6Aav3AYlQ6nfnDoDz0+lUxNiLALvf7XaDNGQ6GANQBKR85V27B4D3QQRw7hGIYlQKWGM79hSweyCUe1blXhEAogfABwHAXAcqSYkxCtHLUK3XBajSc4Dj8dilAeiSAgD2+30BAEKV4GKcAuDqB4TdYwBgPQByCgApUBoE4EJUGvxUjF3Q69/zLw3g/HA45ABKgdIQu+JPIyDnisCfAxAFNFM0EFNQ64gfS0EUoQP8ighrZSjn3oziZEQpauyKbfjbZchHUL/3AS/Dd30gAkxuRACgfO+EWQW8qwI1o+wseNuKcQiESjALvwNoMI0TcRzD4lFcPYwIM+JTF5x6HOs8yI7jeB5oKhpMRFH9UwaSCDB2Jmg4rc6E2TT0biIaG0rQhNqyhpHBcayTTSXH6vcDL7/sdqRK8LkwTsU499E8vRcAojHcZ4AxABdilgrp4lsXk8oVqgwh7+6H3phqd8J0Kk4vbx/+sZqCD/vNLya/5dT9fAH8g1WdNGgwbQAAAABJRU5ErkJggg==";
|
// return new Date(date).toLocaleDateString("en-US", {
|
||||||
|
// month: "short",
|
||||||
export const toDateString = (date: Date) => {
|
// day: "numeric",
|
||||||
return new Date(date).toLocaleDateString("en-US", {
|
// year: "numeric",
|
||||||
month: "short",
|
// });
|
||||||
day: "numeric",
|
// };
|
||||||
year: "numeric",
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
export const random = (min: number, max: number) => {
|
export const random = (min: number, max: number) => {
|
||||||
return Math.floor(Math.random() * (max - min + 1) + min);
|
return Math.floor(Math.random() * (max - min + 1) + min);
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
"@hello-pangea/dnd": "^16.5.0",
|
"@hello-pangea/dnd": "^16.5.0",
|
||||||
"@next-auth/prisma-adapter": "^1.0.7",
|
"@next-auth/prisma-adapter": "^1.0.7",
|
||||||
"@next/third-parties": "^14.1.0",
|
"@next/third-parties": "^14.1.0",
|
||||||
"@prisma/client": "5.11.0",
|
"@prisma/client": "5.12.1",
|
||||||
"@svgr/webpack": "^8.1.0",
|
"@svgr/webpack": "^8.1.0",
|
||||||
"@vercel/analytics": "^1.1.2",
|
"@vercel/analytics": "^1.1.2",
|
||||||
"@vercel/speed-insights": "^1.0.9",
|
"@vercel/speed-insights": "^1.0.9",
|
||||||
@ -80,7 +80,7 @@
|
|||||||
"postcss": "^8.4.33",
|
"postcss": "^8.4.33",
|
||||||
"prettier": "^3.2.4",
|
"prettier": "^3.2.4",
|
||||||
"prettier-plugin-tailwindcss": "^0.5.11",
|
"prettier-plugin-tailwindcss": "^0.5.11",
|
||||||
"prisma": "^5.11.0",
|
"prisma": "^5.12.1",
|
||||||
"tailwindcss": "^3.4.1",
|
"tailwindcss": "^3.4.1",
|
||||||
"tailwindcss-animate": "^1.0.7",
|
"tailwindcss-animate": "^1.0.7",
|
||||||
"typescript": "^5.3.3",
|
"typescript": "^5.3.3",
|
||||||
|
13
start.sh
13
start.sh
@ -1,11 +1,16 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
yarn config set registry 'https://registry.npmmirror.com/'
|
# 加速
|
||||||
yarn config set sharp_binary_host "https://npm.taobao.org/mirrors/sharp"
|
#yarn config set registry 'https://registry.npmmirror.com/'
|
||||||
yarn config set sharp_libvips_binary_host "https://npm.taobao.org/mirrors/sharp-libvips"
|
#yarn config set sharp_binary_host "https://npm.taobao.org/mirrors/sharp"
|
||||||
|
#yarn config set sharp_libvips_binary_host "https://npm.taobao.org/mirrors/sharp-libvips"
|
||||||
|
# 官方
|
||||||
|
yarn config delete registry
|
||||||
|
yarn config delete sharp_binary_host
|
||||||
|
yarn config delete sharp_libvips_binary_host
|
||||||
|
|
||||||
#yarn cache clean
|
#yarn cache clean
|
||||||
yes | yarn install
|
yarn install
|
||||||
yarn run build
|
yarn run build
|
||||||
|
|
||||||
mkdir -p "./node_modules/tiktoken"
|
mkdir -p "./node_modules/tiktoken"
|
||||||
|
Loading…
Reference in New Issue
Block a user