diff --git a/manifest.js b/manifest.js index 2503e3e..b6bf8aa 100755 --- a/manifest.js +++ b/manifest.js @@ -46,7 +46,7 @@ const manifest = { css: ["assets/css/contentStyle.chunk.css"], }, ], - permissions: ["scripting", "storage", "tts", "activeTab"], + permissions: ["scripting", "storage", "activeTab"], optional_host_permissions: ["*://*/*"], optional_permissions: [], host_permissions: ["https://translate.google.com/*", "http://localhost:8765/*", "https://api.lingualeo.com/*"], diff --git a/src/pages/background/index.ts b/src/pages/background/index.ts index 1267f33..a6d0630 100644 --- a/src/pages/background/index.ts +++ b/src/pages/background/index.ts @@ -78,14 +78,5 @@ chrome.runtime.onMessage.addListener(function (message, _sender, sendResponse) { }); } - if (message.type === "speak") { - console.log("speak request: ", message); - chrome.tts.speak(message.text, { lang: message.lang }, function () { - if (chrome.runtime.lastError) { - console.log("Error: " + chrome.runtime.lastError.message); - } - }); - } - return true; }); diff --git a/src/pages/content/components/Subs/SubItemTranslation.tsx b/src/pages/content/components/Subs/SubItemTranslation.tsx index 0b75ae9..5be4cb8 100644 --- a/src/pages/content/components/Subs/SubItemTranslation.tsx +++ b/src/pages/content/components/Subs/SubItemTranslation.tsx @@ -52,7 +52,11 @@ export const SubItemTranslation: FC<{ text: string }> = ({ text }) => { }; const handlePlaySound = async () => { - await chrome.runtime.sendMessage({ type: "speak", text: currentWordTranslation.source, lang: subsLanguage }); + const msg = new SpeechSynthesisUtterance(); + msg.text = currentWordTranslation.source; + msg.lang = subsLanguage; + msg.rate = 0.8; + window.speechSynthesis.speak(msg); }; if (subsLanguage === translateLanguage) { diff --git a/src/pages/popup/Popup.tsx b/src/pages/popup/Popup.tsx index 545eca4..71ece71 100644 --- a/src/pages/popup/Popup.tsx +++ b/src/pages/popup/Popup.tsx @@ -16,7 +16,7 @@ const Popup = () => { const handleRequestPermissions = async () => { const tab = await getTab(); const isGranted = await chrome.permissions.request({ - permissions: ["scripting", "storage", "tts", "activeTab"], + permissions: ["scripting", "storage", "activeTab"], origins: [tab.url], }); if (isGranted) {