Advertisement
Guest User

Untitled

a guest
Feb 21st, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. var Speech = require("net.gotev.speech.Speech");
  2. var SpeechDelegate = require("net.gotev.speech.SpeechDelegate");
  3. var SpeechProgressView = require("net.gotev.speech.ui.SpeechProgressView");
  4. var LinearLayout = require("android.widget.LinearLayout");
  5. var LayoutParams = require("android.widget.LinearLayout.LayoutParams");
  6. var ViewGroupLayoutParams = require("android.view.ViewGroup.LayoutParams");
  7. var Activity = require('android.app.Activity');
  8. var activity = new Activity(Ti.Android.currentActivity);
  9. var speechView = new SpeechProgressView(Ti.Android.currentActivity);
  10. var layout = new LinearLayout(Ti.Android.currentActivity);
  11.  
  12. var success = null;
  13. var progress = null;
  14.  
  15. layout.setLayoutParams(new LayoutParams(ViewGroupLayoutParams.WRAP_CONTENT, ViewGroupLayoutParams.WRAP_CONTENT));
  16. layout.addView(speechView);
  17. speechView.height = 100;
  18. speechView.width = 100;
  19. speechView.zIndex=999999;
  20.  
  21. var speechDelegate = new SpeechDelegate({
  22. onStartOfSpeech: function() {
  23. console.log("Start");
  24. },
  25. onSpeechRmsChanged: function(value) {
  26. console.log("rms: " + value)
  27. },
  28. onSpeechPartialResults: function(results) {
  29. if (progress) {
  30. progress({
  31. value: results
  32. })
  33. }
  34. },
  35. onSpeechResult: function(result) {
  36. if (success) {
  37. success({
  38. result: result
  39. });
  40. }
  41. },
  42. onComplete: function(result) {
  43. if (success) {
  44. success({
  45. result: result
  46. });
  47. }
  48. }
  49. });
  50.  
  51.  
  52.  
  53.  
  54. exports.initialize = function(str) {
  55. Speech.init(Ti.Android.currentActivity);
  56. }
  57. exports.isAvailable = function() {
  58. return true;
  59. }
  60. exports.startRecognition = function(opt) {
  61. success = opt.success;
  62. progress = opt.progress;
  63. Speech.getInstance().startListening(speechView, speechDelegate);
  64. }
  65. exports.say = function(txt) {
  66. success = txt.success;
  67. Speech.getInstance().say(txt,speechDelegate);
  68.  
  69. }
  70. exports.getView = function() {
  71. return layout;
  72. }
  73. //speechView.stop();
  74. // Speech.getInstance().setStopListeningAfterInactivity(1000);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement