Skip to content

Commit

Permalink
fix: use English as alternative language for Google Cloud Speech API
Browse files Browse the repository at this point in the history
Captchas with a non-English locale often have English audio.
  • Loading branch information
dessant committed Dec 13, 2018
1 parent f461b2a commit f13d1ea
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/solve/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -158,20 +158,25 @@ 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: {
content: arrayBufferToBase64(audioContent)
},
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',
Expand Down

0 comments on commit f13d1ea

Please sign in to comment.