Permalink
Browse files

Speaking simskoy

  • Loading branch information...
1 parent 0075913 commit f9a848fe3a01b2d6fed44f9b173b4cb35db33629 @narze committed Jul 23, 2012
Showing with 44 additions and 4 deletions.
  1. +3 −1 app/config.js
  2. +6 −3 app/modules/todo/views.js
  3. +35 −0 assets/js/plugins/speakthai.js
View
@@ -29,6 +29,8 @@ require.config({
// Cross domain ajax
"plugins/jquery.xdomainajax": ["jquery"],
- "plugins/toskoy": []
+ "plugins/toskoy": [],
+
+ "plugins/speakthai": []
}
});
@@ -6,7 +6,8 @@ define([
//Plugins
"plugins/jquery.xdomainajax",
- "plugins/toskoy"
+ "plugins/toskoy",
+ "plugins/speakthai"
],
function(app, Backbone) {
@@ -94,7 +95,7 @@ function(app, Backbone) {
//Default hello message
this.collection.add({
- content: 'ดลีร์จ้',
+ content: 'ษวัสดลีร์จ้',
order: this.collection.first(),
done: false,
me: false
@@ -113,6 +114,8 @@ function(app, Backbone) {
model: item
})).render();
}, this);
+
+ 'สวัสดีจ้ะ'.speakThai();
}
});
@@ -139,7 +142,7 @@ function(app, Backbone) {
var self = this;
$.get('http://www.simsimi.com/func/req?lc=th&msg=' + msg, function(data) {
var json = $.parseJSON($(data.responseText).text().trim());
- self.collection.add(self.reply(json.response.toSkoy()));
+ self.collection.add(self.reply(json.response.speakThai().toSkoy()));
});
this.collection.add(this.newAttributes());
@@ -0,0 +1,35 @@
+//======================================================================
+//http://stackoverflow.com/questions/187098/cross-platform-cross-browser-way-to-play-sound-from-javascript
+//======================================================================
+(function(){
+ var soundEmbed = null;
+
+ function soundPlay(src) {
+ if (!soundEmbed) {
+ soundEmbed = document.createElement("iframe");
+ soundEmbed.setAttribute("src", src);
+ soundEmbed.setAttribute("style", "display:none");
+ soundEmbed.setAttribute("autostart", true);
+ soundEmbed.setAttribute("height", 0);
+ soundEmbed.setAttribute("width", 0);
+ } else {
+ document.body.removeChild(soundEmbed);
+ soundEmbed.removed = true;
+ soundEmbed = null;
+ soundEmbed = document.createElement("iframe");
+ soundEmbed.setAttribute("src", src);
+ soundEmbed.setAttribute("style", "display:none");
+ soundEmbed.setAttribute("autostart", true);
+ soundEmbed.setAttribute("height", 0);
+ soundEmbed.setAttribute("width", 0);
+ }
+ soundEmbed.removed = false;
+ document.body.appendChild(soundEmbed);
+ }
+
+ String.prototype.speakThai = function() {
+ var src = 'http://translate.google.com/translate_tts?tl=th&q=' + this;
+ soundPlay(src);
+ return this;
+ }
+})()

0 comments on commit f9a848f

Please sign in to comment.