fix: set IBM API location instead of URL

pull/73/head
dessant 6 years ago
parent fdb4ccaaa8
commit 0c9a8248bf

@ -34,9 +34,34 @@
"description": "Value of the option."
},
"inputLabel_url": {
"message": "URL",
"description": "Placeholder of the input."
"optionTitle_ibmSpeechApiLoc": {
"message": "API location",
"description": "Title of the option."
},
"optionValue_ibmSpeechApiLoc_frankfurt": {
"message": "Frankfurt",
"description": "Value of the option."
},
"optionValue_ibmSpeechApiLoc_dallas": {
"message": "Dallas",
"description": "Value of the option."
},
"optionValue_ibmSpeechApiLoc_washington": {
"message": "Washington DC",
"description": "Value of the option."
},
"optionValue_ibmSpeechApiLoc_sydney": {
"message": "Sydney",
"description": "Value of the option."
},
"optionValue_ibmSpeechApiLoc_tokyo": {
"message": "Tokyo",
"description": "Value of the option."
},
"inputLabel_apiKey": {
@ -80,12 +105,6 @@
"description": "Error message."
},
"error_missingApiUrl": {
"message":
"API URL missing. Visit the options page to configure the service.",
"description": "Error message."
},
"error_missingApiKey": {
"message":
"API key missing. Visit the options page to configure the service.",
@ -93,7 +112,8 @@
},
"error_internalError": {
"message": "Something went wrong.",
"message":
"Something went wrong. Open the browser console for more details.",
"description": "Error message."
}
}

@ -17,11 +17,12 @@
:label="getText('inputLabel_apiKey')">
</v-textfield>
</div>
<div class="option text-field"
<div class="option select"
v-if="options.speechService === 'ibmSpeechApi'">
<v-textfield v-model="options.ibmSpeechApiUrl"
:label="getText('inputLabel_url')">
</v-textfield>
<v-select :label="getText('optionTitle_ibmSpeechApiLoc')"
v-model="options.ibmSpeechApiLoc"
:options="selectOptions.ibmSpeechApiLoc">
</v-select>
</div>
<div class="option text-field"
v-if="options.speechService === 'ibmSpeechApi'">
@ -58,13 +59,20 @@ export default {
'googleSpeechApiDemo',
'googleSpeechApi',
'ibmSpeechApi'
],
ibmSpeechApiLoc: [
'frankfurt',
'dallas',
'washington',
'sydney',
'tokyo'
]
}),
options: {
speechService: '',
googleSpeechApiKey: '',
ibmSpeechApiUrl: '',
ibmSpeechApiLoc: '',
ibmSpeechApiKey: ''
}
};
@ -80,11 +88,7 @@ export default {
for (const option of Object.keys(this.options)) {
this.options[option] = options[option];
this.$watch(`options.${option}`, async function(value) {
if (
['googleSpeechApiKey', 'ibmSpeechApiUrl', 'ibmSpeechApiKey'].includes(
option
)
) {
if (['googleSpeechApiKey', 'ibmSpeechApiKey'].includes(option)) {
value = value.trim();
}
await storage.set({[option]: value}, 'sync');

@ -5,7 +5,8 @@ import storage from 'storage/storage';
import {getText, waitForElement, arrayBufferToBase64} from 'utils/common';
import {
captchaGoogleSpeechApiLangCodes,
captchaIbmSpeechApiLangCodes
captchaIbmSpeechApiLangCodes,
ibmSpeechApiUrls
} from 'utils/data';
let solverWorking = false;
@ -188,16 +189,9 @@ async function solve() {
if (speechService === 'ibmSpeechApi') {
const {
ibmSpeechApiUrl: apiUrl,
ibmSpeechApiLoc: apiLoc,
ibmSpeechApiKey: apiKey
} = await storage.get(['ibmSpeechApiUrl', 'ibmSpeechApiKey'], 'sync');
if (!apiUrl) {
browser.runtime.sendMessage({
id: 'notification',
messageId: 'error_missingApiUrl'
});
return;
}
} = await storage.get(['ibmSpeechApiLoc', 'ibmSpeechApiKey'], 'sync');
if (!apiKey) {
browser.runtime.sendMessage({
id: 'notification',
@ -207,15 +201,18 @@ async function solve() {
}
const model = captchaIbmSpeechApiLangCodes[lang] || 'en-US_BroadbandModel';
const rsp = await fetch(`${apiUrl}?model=${model}&profanity_filter=false`, {
referrer: '',
mode: 'cors',
method: 'POST',
headers: {
Authorization: 'Basic ' + window.btoa('apiKey:' + apiKey)
},
body: new Blob([audioContent], {type: 'audio/wav'})
});
const rsp = await fetch(
`${ibmSpeechApiUrls[apiLoc]}?model=${model}&profanity_filter=false`,
{
referrer: '',
mode: 'cors',
method: 'POST',
headers: {
Authorization: 'Basic ' + window.btoa('apiKey:' + apiKey)
},
body: new Blob([audioContent], {type: 'audio/wav'})
}
);
if (rsp.status !== 200) {
throw new Error(`API response: ${rsp.status}, ${await rsp.text()}`);

@ -9,7 +9,7 @@ const storage = browser.storage.local;
async function upgrade() {
const changes = {
ibmSpeechApiUrl: '',
ibmSpeechApiLoc: 'frankfurt', // frankfurt, dallas, washington, sydney, tokyo
ibmSpeechApiKey: ''
};
@ -19,7 +19,7 @@ async function upgrade() {
async function downgrade() {
const changes = {};
await storage.remove(['ibmSpeechApiUrl', 'ibmSpeechApiKey']);
await storage.remove(['ibmSpeechApiLoc', 'ibmSpeechApiKey']);
changes.storageVersion = downRevision;
return storage.set(changes);

@ -9,7 +9,7 @@ const storage = browser.storage.sync;
async function upgrade() {
const changes = {
ibmSpeechApiUrl: '',
ibmSpeechApiLoc: 'frankfurt', // frankfurt, dallas, washington, sydney, tokyo
ibmSpeechApiKey: ''
};
@ -19,7 +19,7 @@ async function upgrade() {
async function downgrade() {
const changes = {};
await storage.remove(['ibmSpeechApiUrl', 'ibmSpeechApiKey']);
await storage.remove(['ibmSpeechApiLoc', 'ibmSpeechApiKey']);
changes.storageVersion = downRevision;
return storage.set(changes);

@ -3,7 +3,7 @@ import browser from 'webextension-polyfill';
const optionKeys = [
'speechService',
'googleSpeechApiKey',
'ibmSpeechApiUrl',
'ibmSpeechApiLoc',
'ibmSpeechApiKey'
];
@ -103,8 +103,22 @@ const captchaIbmSpeechApiLangCodes = {
'es-419': 'es-ES_BroadbandModel'
};
// https://cloud.ibm.com/apidocs/speech-to-text#service-endpoint
const ibmSpeechApiUrls = {
frankfurt:
'https://stream-fra.watsonplatform.net/speech-to-text/api/v1/recognize',
dallas: 'https://stream.watsonplatform.net/speech-to-text/api/v1/recognize',
washington:
'https://gateway-wdc.watsonplatform.net/speech-to-text/api/v1/recognize',
sydney:
'https://gateway-syd.watsonplatform.net/speech-to-text/api/v1/recognize',
tokyo:
'https://gateway-tok.watsonplatform.net/speech-to-text/api/v1/recognize'
};
export {
optionKeys,
captchaGoogleSpeechApiLangCodes,
captchaIbmSpeechApiLangCodes
captchaIbmSpeechApiLangCodes,
ibmSpeechApiUrls
};

Loading…
Cancel
Save