From f13d1eaace28681975806b36f28e09d2a5dae420 Mon Sep 17 00:00:00 2001 From: dessant Date: Thu, 13 Dec 2018 16:52:31 +0200 Subject: [PATCH] fix: use English as alternative language for Google Cloud Speech API Captchas with a non-English locale often have English audio. --- src/solve/main.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/solve/main.js b/src/solve/main.js index c59865d..6d6ca0e 100644 --- a/src/solve/main.js +++ b/src/solve/main.js @@ -145,7 +145,7 @@ async function solve() { let apiUrl; if (speechService === 'googleSpeechApiDemo') { apiUrl = - 'https://cxl-services.appspot.com/proxy?url=https://speech.googleapis.com/v1/speech:recognize'; + 'https://cxl-services.appspot.com/proxy?url=https://speech.googleapis.com/v1p1beta1/speech:recognize'; } else { const {googleSpeechApiKey: apiKey} = await storage.get( 'googleSpeechApiKey', @@ -158,8 +158,9 @@ async function solve() { }); return; } - apiUrl = `https://speech.googleapis.com/v1/speech:recognize?key=${apiKey}`; + apiUrl = `https://speech.googleapis.com/v1p1beta1/speech:recognize?key=${apiKey}`; } + const language = captchaGoogleSpeechApiLangCodes[lang] || 'en-US'; const data = { audio: { @@ -167,11 +168,15 @@ async function solve() { }, config: { encoding: 'LINEAR16', - languageCode: captchaGoogleSpeechApiLangCodes[lang] || 'en-US', + languageCode: language, model: 'default', sampleRateHertz: 16000 } }; + if (!['en-US', 'en-GB'].includes(language)) { + data.config.alternativeLanguageCodes = ['en-US']; + } + const rsp = await fetch(apiUrl, { referrer: '', mode: 'cors',