[Speech] Add IVI Speech API support
authorMrunal Kapade <mrunal.kapade@intel.com>
Tue, 8 Apr 2014 01:06:06 +0000 (18:06 -0700)
committerMrunal Kapade <mrunal.kapade@intel.com>
Tue, 8 Apr 2014 01:09:56 +0000 (18:09 -0700)
Adding the synthesizer/vocalizer part for now.
Will add the recognition later.

examples/index.html
examples/speech.html [new file with mode: 0644]
packaging/tizen-extensions-crosswalk.spec
speech/speech.gyp [new file with mode: 0644]
speech/speech_api.js [new file with mode: 0644]
speech/speech_extension.cc [new file with mode: 0644]
speech/speech_extension.h [new file with mode: 0644]
speech/speech_instance.cc [new file with mode: 0644]
speech/speech_instance.h [new file with mode: 0644]
tizen-wrt.gyp

index 35c1a6e..89b8bdd 100644 (file)
@@ -33,5 +33,6 @@ div.block {
 <a href="callhistory.html"><div class="block">Call History</div></a>
 <a href="mediaserver.html"><div class="block">mediaserver</div></a>
 <a href="content.html"><div class="block">content</div></a>
+<a href="speech.html"><div class="block">speech</div></a>
 </body>
 </html>
diff --git a/examples/speech.html b/examples/speech.html
new file mode 100644 (file)
index 0000000..82a1a52
--- /dev/null
@@ -0,0 +1,19 @@
+<html>
+<head>
+<title>Speech Example</title>
+<script>
+function handleTextToSpeech() {
+  var currentText = document.getElementById("inputText").value;
+  var newText = tizen.speech.VocalizeString(currentText);
+  document.getElementById("inputText").value = newText;
+}
+</script>
+</head>
+<body>
+  <div name="input">
+    <div id="instructionLabel">Type in some text</div>
+      <input type="text" id="inputText"><br>
+      <button id="say" onClick="handleTextToSpeech()">Speak Out</button>
+  </div>
+</body>
+</html>
index 67d73c7..ddbdade 100644 (file)
@@ -46,6 +46,7 @@ BuildRequires: pkgconfig(capi-content-media-content)
 BuildRequires: pkgconfig(dbus-glib-1)
 # Evas.h is required by capi-web-favorites.
 BuildRequires: pkgconfig(evas)
+BuildRequires: pkgconfig(gio-2.0)
 BuildRequires: pkgconfig(glib-2.0)
 BuildRequires: pkgconfig(tapi)
 BuildRequires: pkgconfig(libudev)
diff --git a/speech/speech.gyp b/speech/speech.gyp
new file mode 100644 (file)
index 0000000..4252292
--- /dev/null
@@ -0,0 +1,28 @@
+{
+  'includes':[
+    '../common/common.gypi',
+  ],
+  'targets': [
+    {
+      'target_name': 'tizen_speech',
+      'type': 'loadable_module',
+      'variables': {
+        'packages': [
+          'gio-2.0',
+        ],
+      },
+      'includes': [
+        '../common/pkg-config.gypi',
+      ],
+      'sources': [
+        'speech_api.js',
+        'speech_extension.cc',
+        'speech_extension.h',
+        'speech_instance.cc',
+        'speech_instance.h',
+        '../common/extension.cc',
+        '../common/extension.h',        
+      ],
+    },
+  ],
+}
diff --git a/speech/speech_api.js b/speech/speech_api.js
new file mode 100644 (file)
index 0000000..c76b1f8
--- /dev/null
@@ -0,0 +1,23 @@
+// Copyright (c) 2014 Intel Corporation. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+var postMessage = function(msg) {
+  extension.postMessage(JSON.stringify(msg));
+};
+
+var sendSyncMessage = function(msg) {
+  return extension.internal.sendSyncMessage(JSON.stringify(msg));
+};
+
+exports.VocalizeString = function(speakText) {
+  try {
+    var r = JSON.parse(sendSyncMessage({
+      'cmd': 'VocalizeString',
+      'text': speakText
+    }));
+  } catch (e) {
+    console.error('Parsing error: ', e);
+  }
+  return r['text'];
+};
diff --git a/speech/speech_extension.cc b/speech/speech_extension.cc
new file mode 100644 (file)
index 0000000..789b885
--- /dev/null
@@ -0,0 +1,25 @@
+// Copyright (c) 2014 Intel Corporation. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "speech/speech_extension.h"
+
+#include "speech/speech_instance.h"
+
+common::Extension* CreateExtension() {
+  return new SpeechExtension();
+}
+
+// This will be generated from speech_api.js
+extern const char kSource_speech_api[];
+
+SpeechExtension::SpeechExtension() {
+  SetExtensionName("tizen.speech");
+  SetJavaScriptAPI(kSource_speech_api);
+}
+
+SpeechExtension::~SpeechExtension() {}
+
+common::Instance* SpeechExtension::CreateInstance() {
+  return new SpeechInstance;
+}
diff --git a/speech/speech_extension.h b/speech/speech_extension.h
new file mode 100644 (file)
index 0000000..bf157d8
--- /dev/null
@@ -0,0 +1,20 @@
+// Copyright (c) 2014 Intel Corporation. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef SPEECH_SPEECH_EXTENSION_H_
+#define SPEECH_SPEECH_EXTENSION_H_
+
+#include "common/extension.h"
+
+class SpeechExtension : public common::Extension {
+ public:
+  SpeechExtension();
+  virtual ~SpeechExtension();
+
+ private:
+  // common::Extension implementation
+  virtual common::Instance* CreateInstance();
+};
+
+#endif  // SPEECH_SPEECH_EXTENSION_H_
diff --git a/speech/speech_instance.cc b/speech/speech_instance.cc
new file mode 100644 (file)
index 0000000..cb9d1db
--- /dev/null
@@ -0,0 +1,51 @@
+// Copyright (c) 2014 Intel Corporation. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "speech/speech_instance.h"
+
+#include <gio/gio.h>
+#include <string>
+
+SpeechInstance::SpeechInstance() {}
+
+SpeechInstance::~SpeechInstance() {}
+
+void SpeechInstance::HandleMessage(const char* message) {}
+
+void SpeechInstance::HandleSyncMessage(const char* message) {
+  picojson::value v;
+  std::string err;
+  picojson::parse(v, message, message + strlen(message), &err);
+  if (!err.empty())
+    return;
+
+  picojson::value::object o;
+  std::string cmd = v.get("cmd").to_str();
+  if (cmd == "VocalizeString")
+    o = HandleVocalizeString(v);
+
+  SendSyncReply(picojson::value(o).serialize().c_str());
+}
+
+const picojson::value::object SpeechInstance::HandleVocalizeString(
+    const picojson::value& msg) {
+  picojson::value::object o;
+
+  std::string speakText = msg.get("text").to_str();
+  g_dbus_connection_call(g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL),
+      "org.tizen.srs",
+      "/tts",
+      "org.tizen.srs",
+      "synthesize",
+      g_variant_new("(ss)", speakText.c_str(), "english"),
+      NULL,
+      G_DBUS_CALL_FLAGS_NONE,
+      -1,
+      NULL,
+      NULL,
+      NULL);
+
+  o["text"] = picojson::value("");
+  return o;
+}
diff --git a/speech/speech_instance.h b/speech/speech_instance.h
new file mode 100644 (file)
index 0000000..e9c05a9
--- /dev/null
@@ -0,0 +1,25 @@
+// Copyright (c) 2014 Intel Corporation. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef SPEECH_SPEECH_INSTANCE_H_
+#define SPEECH_SPEECH_INSTANCE_H_
+
+#include "common/extension.h"
+#include "common/picojson.h"
+
+class SpeechInstance : public common::Instance {
+ public:
+  SpeechInstance();
+  virtual ~SpeechInstance();
+
+ private:
+  // common::Instance implementation.
+  virtual void HandleMessage(const char* msg);
+  virtual void HandleSyncMessage(const char* message);
+
+  const picojson::value::object
+  HandleVocalizeString(const picojson::value& msg);
+};
+
+#endif  // SPEECH_SPEECH_INSTANCE_H_
index 29dcc2b..f405988 100644 (file)
@@ -14,6 +14,7 @@
         'network_bearer_selection/network_bearer_selection.gyp:*',
         'notification/notification.gyp:*',
         'power/power.gyp:*',
+        'speech/speech.gyp:*',
         'system_info/system_info.gyp:*',
         'system_setting/system_setting.gyp:*',
         'time/time.gyp:*',