XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet
公开
关注 0 Fork 0 Star 1
返回提交历史

XFEstudio/gpt4free

Fix SpeechRecognition on Phone

7194c70d
Heiner Lohaus <hlohaus@users.noreply.github.com>
提交于

代码差异

1 个文件 +12 -4
Modified g4f/gui/client/static/js/chat.v1.js +12 -4
@@ -1074,7 +1074,7 @@ async function load_version() {
1074 1074 }
1075 1075 setTimeout(load_version, 2000);
1076 1076
1077 for (const el of [imageInput, cameraInput]) {
1077 [imageInput, cameraInput].forEach((el) => {
1078 1078 el.addEventListener('click', async () => {
1079 1079 el.value = '';
1080 1080 if (imageInput.dataset.src) {
@@ -1082,7 +1082,7 @@ for (const el of [imageInput, cameraInput]) {
1082 1082 delete imageInput.dataset.src
1083 1083 }
1084 1084 });
1085 }
1085 });
1086 1086
1087 1087 fileInput.addEventListener('click', async (event) => {
1088 1088 fileInput.value = '';
@@ -1261,9 +1261,11 @@ if (SpeechRecognition) {
1261 1261 recognition.interimResults = true;
1262 1262 recognition.maxAlternatives = 1;
1263 1263
1264 let shouldStop = false;
1264 1265 function may_stop() {
1265 1266 if (microLabel.classList.contains("recognition")) {
1266 1267 recognition.stop();
1268 shouldStop = true
1267 1269 }
1268 1270 }
1269 1271
@@ -1277,8 +1279,12 @@ if (SpeechRecognition) {
1277 1279 timeoutHandle = window.setTimeout(may_stop, 10000);
1278 1280 };
1279 1281 recognition.onend = function() {
1280 microLabel.classList.remove("recognition");
1281 messageInput.focus();
1282 if (shouldStop) {
1283 microLabel.classList.remove("recognition");
1284 messageInput.focus();
1285 } else {
1286 recognition.start();
1287 }
1282 1288 };
1283 1289 recognition.onresult = function(event) {
1284 1290 if (!event.results) {
@@ -1310,10 +1316,12 @@ if (SpeechRecognition) {
1310 1316 microLabel.addEventListener("click", () => {
1311 1317 if (microLabel.classList.contains("recognition")) {
1312 1318 window.clearTimeout(timeoutHandle);
1319 shouldStop = true;
1313 1320 recognition.stop();
1314 1321 } else {
1315 1322 const lang = document.getElementById("recognition-language")?.value;
1316 1323 recognition.lang = lang || navigator.language;
1324 shouldStop = false;
1317 1325 recognition.start();
1318 1326 }
1319 1327 });