Merge pull request #58 from sijinhui/dev

Dev
This commit is contained in:
sijinhui 2024-04-12 16:41:36 +08:00 committed by GitHub
commit 82af6ed98c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 84 additions and 76 deletions

View File

@ -101,9 +101,7 @@ export default function VoiceInput({
);
}
const startRecognition = async () => {
let token = await get_access_token();
const startRecognition = () => {
if (voiceInputLoading) {
recognizer.current?.close();
setVoiceInputLoading(false);
@ -116,37 +114,42 @@ export default function VoiceInput({
setTempUserInput(userInput); // 开始的时候拷贝一份用于复原
setVoiceInputText("");
const speechConfig = ms_audio_sdk.SpeechConfig.fromAuthorizationToken(
token,
"eastasia",
);
const audioConfig = ms_audio_sdk.AudioConfig.fromDefaultMicrophoneInput();
speechConfig.speechRecognitionLanguage = "zh-CN";
speechConfig.setProperty(
ms_audio_sdk.PropertyId.SpeechServiceConnection_EndSilenceTimeoutMs,
"3500",
);
recognizer.current = new ms_audio_sdk.SpeechRecognizer(
speechConfig,
audioConfig,
);
recognizer.current.recognizing = onRecognizing; // 自定义分段显示
recognizer.current.canceled = onCanceled; // 自定义中断
recognizer.current.recognizeOnceAsync(
(result) => {
onRecognizedResult(result);
setUserInput(
tempUserInput + (voiceInputText ?? "") + `${result.text ?? ""}`,
);
setTempUserInput("");
setVoiceInputText("");
setVoiceInputLoading(false);
},
(err) => {
console.error("Recognition error: ", err); // 错误处理
setVoiceInputLoading(false);
},
);
const getToken = async () => {
return await get_access_token();
};
getToken().then((token) => {
const speechConfig = ms_audio_sdk.SpeechConfig.fromAuthorizationToken(
token,
"eastasia",
);
const audioConfig = ms_audio_sdk.AudioConfig.fromDefaultMicrophoneInput();
speechConfig.speechRecognitionLanguage = "zh-CN";
speechConfig.setProperty(
ms_audio_sdk.PropertyId.SpeechServiceConnection_EndSilenceTimeoutMs,
"3500",
);
recognizer.current = new ms_audio_sdk.SpeechRecognizer(
speechConfig,
audioConfig,
);
recognizer.current.recognizing = onRecognizing; // 自定义分段显示
recognizer.current.canceled = onCanceled; // 自定义中断
recognizer.current.recognizeOnceAsync(
(result) => {
onRecognizedResult(result);
setUserInput(
tempUserInput + (voiceInputText ?? "") + `${result.text ?? ""}`,
);
setTempUserInput("");
setVoiceInputText("");
setVoiceInputLoading(false);
},
(err) => {
console.error("Recognition error: ", err); // 错误处理
setVoiceInputLoading(false);
},
);
});
};
const icon = useMemo(() => {

View File

@ -8,18 +8,18 @@ export function getTokenLength(input: string): number {
return encoding.encode(input).length;
}
export async function fetcher<JSON = any>(
input: RequestInfo,
init?: RequestInit,
): Promise<JSON> {
const response = await fetch(input, { ...init, cache: "no-store" });
// export async function fetcher<JSON = any>(
// input: RequestInfo,
// init?: RequestInit,
// ): Promise<JSON> {
// 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) => {
if (!str) return "";
@ -29,33 +29,33 @@ export const truncate = (str: string, num: number) => {
return str.slice(0, num) + "...";
};
export const getBlurDataURL = async (url: string | null) => {
if (!url) {
return "data:image/webp;base64,AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";
}
try {
const response = await fetch(
`https://wsrv.nl/?url=${url}&w=50&h=50&blur=5`,
);
const buffer = await response.arrayBuffer();
const base64 = Buffer.from(buffer).toString("base64");
// export const getBlurDataURL = async (url: string | null) => {
// if (!url) {
// return "data:image/webp;base64,AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";
// }
// try {
// const response = await fetch(
// `https://wsrv.nl/?url=${url}&w=50&h=50&blur=5`,
// );
// const buffer = await response.arrayBuffer();
// 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}`;
} catch (error) {
return "data:image/webp;base64,AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";
}
};
// export const placeholderBlurhash =
// "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==";
export const placeholderBlurhash =
"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==";
export const toDateString = (date: Date) => {
return new Date(date).toLocaleDateString("en-US", {
month: "short",
day: "numeric",
year: "numeric",
});
};
// export const toDateString = (date: Date) => {
// return new Date(date).toLocaleDateString("en-US", {
// month: "short",
// day: "numeric",
// year: "numeric",
// });
// };
export const random = (min: number, max: number) => {
return Math.floor(Math.random() * (max - min + 1) + min);

View File

@ -21,7 +21,7 @@
"@hello-pangea/dnd": "^16.5.0",
"@next-auth/prisma-adapter": "^1.0.7",
"@next/third-parties": "^14.1.0",
"@prisma/client": "5.11.0",
"@prisma/client": "5.12.1",
"@svgr/webpack": "^8.1.0",
"@vercel/analytics": "^1.1.2",
"@vercel/speed-insights": "^1.0.9",
@ -80,7 +80,7 @@
"postcss": "^8.4.33",
"prettier": "^3.2.4",
"prettier-plugin-tailwindcss": "^0.5.11",
"prisma": "^5.11.0",
"prisma": "^5.12.1",
"tailwindcss": "^3.4.1",
"tailwindcss-animate": "^1.0.7",
"typescript": "^5.3.3",

View File

@ -1,11 +1,16 @@
#!/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 sharp_libvips_binary_host "https://npm.taobao.org/mirrors/sharp-libvips"
# 加速
#yarn config set registry 'https://registry.npmmirror.com/'
#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
yes | yarn install
yarn install
yarn run build
mkdir -p "./node_modules/tiktoken"