[W3C-Speech]: Fix issues found in extension code
authorAmarnath Valluri <amarnath.valluri@linux.intel.com>
Tue, 25 Nov 2014 12:55:04 +0000 (14:55 +0200)
committerKrisztian Litkey <krisztian.litkey@intel.com>
Tue, 16 Dec 2014 19:28:38 +0000 (21:28 +0200)
- Timing issues in object registraion(sync calls)
- Result event generation

Change-Id: I8142f9aa2acb9336c4bc1b638d2f4f4414306150

src/plugins/client-api/w3c-speech/crosswalk-extension/speech_api.js
src/plugins/client-api/w3c-speech/crosswalk-extension/speech_instance.cc
src/plugins/client-api/w3c-speech/crosswalk-extension/speech_instance.h

index 7b6d845..9a80407 100644 (file)
@@ -72,6 +72,7 @@
       var args = { };
       var obj = _dynamic_objects[msg.id];
       if (!obj) {
+        /* Synthesizer events */
         if (msg.event == 'pending') {
           _v8tools.forceSetProperty(exports, 'pending', msg.state);
         } else if (msg.event == 'speaking') {
       } else if (msg.event == 'result') {
         // currently we support only signle shot result
         args.resultIndex = 0;
-        args.results = msg.results;
         args.interpretation = null;
         args.emma = null;
+        var res = new SpeechRecognitionResult(msg.final);
+        msg.results.forEach(function(alternative) {
+          res.push({
+            'transcript': alternative.transcript,
+            'confidence': alternative.confidence
+          });
+        });
+        DBG('Result Length: ' + res.length);
+        args.results = [ res ];
       } else if (msg.event == 'nomatch') {
         args.resultIndex = 0;
         args.results = null;
           args.name = null;
         }
       } else if (msg.event == 'end') {
-        if (obj.type == 'recognizer') {
+        if (obj._type == 'recognizer') {
         } else {
           args.charIndex = msg.charIndex;
           args.elapsedTime = msg.elapsedTime;
   // SpeechRecognition : Speech -> Text
   //
   function SpeechRecognitionResult(is_final) {
-    this.push.apply(this, arguments);
 
-    _addConstProperty(this, 'final', is_final || true);
+    _addConstProperty(this, 'isFinal', is_final || true);
 
     this.item = function(index) {
       return this[index];
     };
-
-    this.toJSON = function() {
-      var a = [];
-      for (var i = 0; i < this.length; i++) {
-        a[i] = this[i];
-      }
-      return a;
-    };
-
   }
   SpeechRecognitionResult.prototype = Object.create(Array.prototype);
   SpeechRecognitionResult.prototype.construrctor = SpeechRecognitionResult;
   function SpeechRecognition() {
     this._id = -1;
     this._is_active = 0;
+    this._type = 'recognizer';
 
     EventTarget.call(this, [
       'audiostart',
index 0428d5c..8934942 100644 (file)
@@ -25,6 +25,8 @@
 void SpeechInstance::SetupMainloop(void* data) {
   SpeechInstance* self = reinterpret_cast<SpeechInstance*>(data);
 
+  DBG("Running Mainloop...");
+
   g_main_loop_run(self->main_loop_);
 }
 #endif  // TIZEN
@@ -40,7 +42,8 @@ SpeechInstance::SpeechInstance()
     , channel_(NULL)
     , watcher_id_(0)
     , pending_request_timer_(0)
-    , pending_reply_timer_(0) {
+    , pending_reply_timer_(0)
+    , is_waiting_for_reply_(false) {
 #ifdef TIZEN
     thread_.detach();
 #endif  // TIZEN
@@ -110,6 +113,8 @@ gboolean SpeechInstance::IOWatchCb(GIOChannel *c,
       char *reply = NULL;
       uint32_t size = 0;
 
+      if (self->is_waiting_for_reply_) break;
+
       if ((size = self->ReadReply(&reply))) {
         self->PostMessage(reply);
         free(reply);
@@ -262,6 +267,8 @@ void SpeechInstance::HandleSyncMessage(const char* message) {
     obj["message"] = picojson::value("server connection failure");
     out = picojson::value(obj);
   } else {
+
+    is_waiting_for_reply_ = true;
     picojson::parse(v, message, message + strlen(message), &err);
     if (!err.empty())
       return;
@@ -273,6 +280,7 @@ void SpeechInstance::HandleSyncMessage(const char* message) {
       uint32_t size;
 
       if ((size = ReadReply(&reply)) != 0) {
+        is_waiting_for_reply_ = false;
         picojson::parse(out, reply, reply + size, &err);
         free(reply);
         if (!err.empty()) {
index c15b813..28b66e2 100644 (file)
@@ -47,5 +47,6 @@ class SpeechInstance : public common::Instance {
   guint watcher_id_;
   guint pending_request_timer_;
   guint pending_reply_timer_;
+  bool is_waiting_for_reply_;
 };
 #endif  // SPEECH_SPEECH_INSTANCE_H_