Merge pull request from picklesrus/speech-language

Send the language code of the project viewer to the server
This commit is contained in:
picklesrus 2018-09-24 14:26:14 -07:00 committed by GitHub
commit b063226fd7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -199,6 +199,14 @@ class Scratch3Speech2TextBlocks {
return words;
}
/**
* Get the viewer's language code.
* @return {string} the language code.
*/
_getViewerLanguageCode () {
return formatMessage.setup().locale || navigator.language || navigator.userLanguage || 'en-US';
}
/**
* Resets all things related to listening. Called on Red Stop sign button.
* - suspends audio processing
@ -547,10 +555,12 @@ class Scratch3Speech2TextBlocks {
// it, start streaming the audio bytes to the server and listening for
// transcriptions.
this._socket.addEventListener('message', this._socketMessageCallback, {once: true});
const langCode = this._getViewerLanguageCode();
this._socket.send(JSON.stringify(
{
sampleRate: this._context.sampleRate,
phrases: this._phraseList
phrases: this._phraseList,
locale: langCode
}
));
}