add safari support for TTS.
authorrajbot <raj@archive.org>
Wed, 29 Sep 2010 20:44:06 +0000 (20:44 +0000)
committerrajbot <raj@archive.org>
Wed, 29 Sep 2010 20:44:06 +0000 (20:44 +0000)
BookReader/BookReader.js
BookReaderIA/datanode/BookReaderGetTextWrapper.php
BookReaderIA/inc/BookReader.inc

index a08c467..bfcf5ac 100644 (file)
@@ -110,6 +110,7 @@ function BookReader() {
     this.ttsPosition    = -1;    //chunk (paragraph) number
     this.ttsBuffering   = false;
     this.ttsPoller      = null;
+    this.ttsFormat      = null;
     
     return this;
 };
@@ -3824,7 +3825,11 @@ BookReader.prototype.ttsStart = function () {
     console.log('starting readAloud');
     this.ttsPlaying = true;
     this.ttsIndex = this.currentIndex();
-    this.ttsGetText(this.ttsIndex, 'ttsStartCB');
+    this.ttsFormat = 'mp3';
+    if ($.browser.mozilla) {
+        this.ttsFormat = 'ogg';
+    }
+    this.ttsGetText(this.ttsIndex, 'ttsStartCB');    
 }
 
 // ttsStop()
@@ -3848,6 +3853,7 @@ BookReader.prototype.ttsStop = function () {
 //______________________________________________________________________________
 BookReader.prototype.ttsGetText = function(index, callback) {
     var url = 'http://'+this.server+'/BookReader/BookReaderGetTextWrapper.php?path='+this.bookPath+'_djvu.xml&page='+index;
+    console.log('ttsGetText: ' + url);
     this.ttsAjax = $.ajax({url:url, dataType:'jsonp', jsonpCallback:callback});
 }
 
@@ -3873,12 +3879,15 @@ BookReader.prototype.ttsStartCB = function (data) {
     
     this.ttsShowPopup();
     
+    ///// whileloading: broken on safari
+    ///// onload fires on safari, but *after* the sound starts playing..
     this.ttsPosition = -1;    
     var snd = soundManager.createSound({
      id: 'chunk'+this.ttsIndex+'-0',
-     //url: 'http://home.us.archive.org/~rkumar/arctic.ogg',     
-     url: 'http://home.us.archive.org/~rkumar/getOgg.php?string=' + escape(data[0][0]) + '&f=.ogg', //the .ogg is to trick SoundManager2 to use the HTML5 audio player
-     whileloading: function(){if (this.bytesLoaded == this.bytesTotal) {$(this.br.popup).remove(); this.br.popup=null;}} //onload never fires...
+     //url: 'http://home.us.archive.org/~rkumar/arctic.ogg',
+     url: 'http://'+this.server+'/getTTS.php?string=' + escape(data[0][0]) + '&format=.'+this.ttsFormat, //the .ogg is to trick SoundManager2 to use the HTML5 audio player
+     whileloading: function(){if (this.bytesLoaded == this.bytesTotal) this.br.ttsRemovePopup();}, //onload never fires in FF...
+     onload: function(){this.br.ttsRemovePopup();} //whileloading never fires in safari...
     });    
     snd.br = this;
     snd.load();
@@ -3911,6 +3920,13 @@ BookReader.prototype.ttsShowPopup = function() {
     this.popup.innerHTML = htmlStr;
 }
 
+// ttsRemovePopup
+//______________________________________________________________________________
+BookReader.prototype.ttsRemovePopup = function() {
+    $(this.popup).remove(); 
+    this.popup=null;
+}
+
 // ttsNextPageCB
 //______________________________________________________________________________
 BookReader.prototype.ttsNextPageCB = function (data) {
@@ -3929,7 +3945,7 @@ BookReader.prototype.ttsNextPageCB = function (data) {
 BookReader.prototype.ttsLoadChunk = function (page, pos, string) {
     var snd = soundManager.createSound({
      id: 'chunk'+page+'-'+pos,
-     url: 'http://home.us.archive.org/~rkumar/getOgg.php?string=' + escape(string) + '&f=.ogg' //the .ogg is to trick SoundManager2 to use the HTML5 audio player
+     url: 'http://'+this.server+'/getTTS.php?string=' + escape(string) + '&format=.'+this.ttsFormat //the .ogg is to trick SoundManager2 to use the HTML5 audio player
     });
     snd.br = this;
     snd.load()
@@ -3945,8 +3961,7 @@ BookReader.prototype.ttsLoadChunk = function (page, pos, string) {
 // continues after animation is finished.
 
 BookReader.prototype.ttsNextChunk = function () {
-    console.log(this);
-    console.log(this.ttsPosition);
+    console.log('nextchunk pos=' + this.ttsPosition);
     
     if (-1 != this.ttsPosition) {
         soundManager.destroySound('chunk'+this.ttsIndex+'-'+this.ttsPosition);
@@ -4084,7 +4099,7 @@ BookReader.prototype.ttsPrefetchAudio = function () {
 BookReader.prototype.ttsPlay = function () {
         
     var chunk = this.ttsChunks[this.ttsPosition];
-    console.log('position = ' + this.ttsPosition);
+    console.log('ttsPlay position = ' + this.ttsPosition);
     console.log('chunk = ' + chunk);
     console.log(this.ttsChunks);
 
@@ -4099,6 +4114,7 @@ BookReader.prototype.ttsPlay = function () {
         
     //play current chunk
     if (false == this.ttsBuffering) {
+        console.log('calling play');
         soundManager.play('chunk'+this.ttsIndex+'-'+this.ttsPosition,{onfinish:function(){br.ttsNextChunk();}});
     } else {
         console.log('playing current chunk, but next chunk is not buffered yet!');
index 436bed7..ca4d05b 100644 (file)
@@ -25,5 +25,6 @@ This file is part of BookReader.
 $path=$_GET['path'];
 $page=$_GET['page'];
 $callback=$_GET['callback'];
+header('Content-Type: application/javascript');
 passthru("python BookReaderGetText.py $path $page $callback");
-?>
\ No newline at end of file
+?>
index 762a1bf..8d12424 100644 (file)
@@ -133,9 +133,10 @@ class BookReader
     <script type="text/javascript" src="/bookreader/BookReader.js?v=<? echo($version); ?>"></script>
     <script type="text/javascript" src="/bookreader/soundmanager/soundmanager2.js?v=<? echo($version); ?>"></script>
     <script>
-        soundManager.debugMode = false;
+        soundManager.debugMode = true;
         soundManager.url = '/bookreader/soundmanager/swf/';       
         soundManager.useHTML5Audio = true;
+        soundManager.flashVersion = 9; //flash 8 version of swf is buggy when calling play() on a sound that is still loading
     </script>
 </head>
 <body style="background-color: #FFFFFF;">