Skip to content

Instantly share code, notes, and snippets.

@xydrolase
Last active August 29, 2015 14:05
Show Gist options
  • Select an option

  • Save xydrolase/618a8eabcc7d93cc3508 to your computer and use it in GitHub Desktop.

Select an option

Save xydrolase/618a8eabcc7d93cc3508 to your computer and use it in GitHub Desktop.
Use Bing Translator as the TTS engine for Duolingo. To install, click on the **Raw** button below (for `LingoBingTTS.user.js`). Scroll down for more details.

LingoBingTTS.user.js

Introduction

From time to time you may feel bored listening to Duo's synthesized voice and want to try something different. Personally I find Microsoft's Bing Translator synthesizes better voices than Duo's. And if you have the same preference as mine, you may want to give this script a try.

Technically, this script intercepts the Duolingo's TTS (Text-to-speech) API calls and redirects it to Microsoft's Bing Translator's TTS engine. So that you can hear a different voice.

Installation

To install, you need to first install extensions for your browser:

  • For Chrome/Safari, please use Tampermonkey
  • For Firefox, install Greasemonkey

After installing the extension, you can simply click on the Raw button for LingoBingTTS.user.js. After clicking you should see a new window/tab seeking your permission to install the script.

Disclaimer

This script is only a technical demo. Please use it at your own caution.

I blatantly use the application id (AppId) for the Bing Translator's website. This AppId may expire after a while. If you notice that the script stop working (no voice when there should be one), it is mostly likely that the AppId is revoked by Microsoft. You can bug me on Duolingo (username: xydrolase) or leave a comment here so that I can update the AppId.

// ==UserScript==
// @name LingoBingTTS
// @namespace http://xydrolase.me
// @version 0.1
// @description Technical demo
// @match https://www.duolingo.com/*
// ==/UserScript==
//
(function($) {
var bingAPI = "https://api.microsofttranslator.com/v2/http.svc/Speak?";
var appId = encodeURIComponent("TDlJYPO8pY0n2s6f5PM7nTj4cZi-6IQ3JRdBTIQQw4gk*");
if (typeof duo != 'undefined' && typeof $.tts_super == 'undefined') {
$.fn.tts_super = $.fn.tts;
$.fn.tts = function(d) {
console.log(d.absoluteURL);
if (typeof d.absoluteURL != 'undefined') {
var aurl = d.absoluteURL;
var regex_sen = /tts\/\w+\/sentence\/(\w+)$/;
var _this = this;
if (regex_sen.test(aurl)) {
var sen_id = regex_sen.exec(aurl)[1];
var sentence = new duo.Sentence({id: sen_id});
sentence.fetch({
data: {},
success: function(f) {
var s = f.toJSON();
var quoted_text = encodeURIComponent(s.text.replace("/", " "));
d.absoluteURL = bingAPI + "language=" + s.language + "&format=audio/mp3" +
"&options=MaxQuality&appid=" + appId +
"&text=" + quoted_text;
_this.each(function() {
$(this).tts_super(d);
});
}
});
}
else {
this.each(function() {
$(this).tts_super(d);
});
}
}
else {
this.each(function() {
$(this).tts_super(d);
});
}
return this;
}
}
}(jQuery));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment