Giter Site home page Giter Site logo

hyperloop-modules / titanium-speech Goto Github PK

View Code? Open in Web Editor NEW
21.0 7.0 9.0 8.88 MB

Use the iOS 10 SFSpeechRecognizer API in JavaScript with Appcelerator Hyperloop.

JavaScript 83.32% Python 16.68%
appcelerator-hyperloop ios speech-recognition native javascript hyperloop

titanium-speech's Introduction

Ti.Speech

iOS 10 speech-recognition with Appcelerator Hyperloop.

Requirements

  • Titanium SDK 5.5.0.GA+
  • Hyperloop 2.0.0+
  • Xcode 8+
  • Include the following keys in the plist-section of your tiapp.xml:
<key>NSSpeechRecognitionUsageDescription</key>
<string>Can we parse your spoken words?</string>

<key>NSMicrophoneUsageDescription</key>
<string>Can we use the microphone for real-time speech recognition?</string>

Usage

Getting started using example app

  1. Copy example app from here: https://github.com/hyperloop-modules/ti.speech/tree/master/example
  2. Import app into your account using appc new --import
  3. Enable Hyperloop platform services when being asked
  4. Run the app with appc run -p ios -I 10.0

Creating a new app

  1. Create a new project with appc new -p ios
  2. Enable Hyperloop platform services when being asked
  3. Copy the ti.speech in your project and use code from examples (or example app)
  4. Run the app with appc run -p ios -I 10.0

Examples

You can use speech recognition with real-time audio or with pre-recorded media files (audio or video). See example file for more details.

Recognize from File URL

var TiSpeech = require("ti.speech");
TiSpeech.initialize("en_US");  // locale is optional

var win = Ti.UI.createWindow({
    backgroundColor: "#fff"
});

var btn = Ti.UI.createButton({
    title: "Recognize pre-recorded speech"
});

if (!TiSpeech.isSupported()) {
    alert("Speech recognition is not available on this device!");
    btn.setEnabled(false);
}

btn.addEventListener("click", function() {
    TiSpeech.recognize({
        type: TiSpeech.SOURCE_TYPE_URL, // optional, as it defaults to this if url is defined
        url: "one_more_thing.mp3",
        progress: function(e) {
            Ti.API.info(e.value);
        }
    });
});

win.add(btn);
win.open();

Recognize from Audio Input

var TiSpeech = require("ti.speech");
TiSpeech.initialize("en_US");  // locale is optional

var win = Ti.UI.createWindow({
    backgroundColor: "#fff"
});

var btn = Ti.UI.createButton({
    title: "Recognize real-time speech"
});

if (!TiSpeech.isAvailable()) {
    alert("Speech recognition is not available on this device!");
    btn.setEnabled(false);
}

btn.addEventListener("click", function() {
    TiSpeech.startRecognition({
        type: TiSpeech.SOURCE_TYPE_MICROPHONE, // optional, as it defaults to this if url is undefined		
        progress: function(e) {
            Ti.API.info(e.value);
        }
    });
});

win.add(btn);
win.open();

Author

License

Apache 2.0

Contributing

Code contributions are greatly appreciated, please submit a new pull request!

titanium-speech's People

Contributors

brentonhouse avatar hansemannn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

titanium-speech's Issues

Crash with iOS 16.4, Titanium SDK 12.2.1GA, Hyperloop 7.0.6

I used titamium.speech on my app without problems xcode 14.3.1 sdk 12.1.1 hyperloop 7.0.5, but when I updated to xcode 15.0.1 sdk 12.2.1 and hyperloop 7.0.6 I got this error:
[ERROR] /ti.kernel.js:792
[ERROR] throws new error(Requested form not found: ${request}); // TODO Set the 'code' property to 'MODULE_NOT_FOUND' to match Node?
[ERROR] ^
[ERROR]: Required module not found: AVFAudio
[ERROR] on require (/ti.kernel.js:792:24)
[ERROR] at (/ti.speech.js:21:35)
[ERROR] on loading (/ti.kernel.js:634:24)
[ERROR] in loadJavascriptText (/ti.kernel.js:927:20)
[ERROR] in loadAsFileOrDirectory (/ti.kernel.js:904:37)
[ERROR] on require (/ti.kernel.js:785:46)
[ERROR] in controller (/alloy/controllers/cerca.js:1625:17804)
[ERROR] in (/alloy.js:427:48)
[ERROR] when opening (/alloy/controllers/home.js:57:27)
[ERROR] on onSearch (/alloy/controllers/listaProdotti.js:767:37)
[ERROR] Foundation 0x000000018aad4794 _NSDescriptionWithLocaleFunc + 80
[ERROR] CoreFoundation 0x000000018bb1b1dc B37A1273-B0C2-312E-9E0B-7143FB645C69+127452
[ERROR] CoreFoundation 0x000000018bb18788 _CFStringCreateWithFormatAndArgumentsReturningMetadata + 184
[ERROR] CoreFoundation 0x000000018bb186c4 _CFStringCreateWithFormatAndArgumentsAux2 + 44
[ERROR] TitaniumKit 0x0000000102c25a60 TiLogMessage + 52
[ERROR] TitaniumKit 0x0000000102c550f4 -[TiExceptionHandler reportScriptError:] + 60
[ERROR] TitaniumKit 0x0000000102c46908 TiBindingEventProcess + 668
[ERROR] TitaniumKit 0x0000000102c600f8 -[Invocation KrollContext:] + 84
[ERROR] TitaniumKit 0x0000000102c60160 -[KrollContext queue:] + 84
[ERROR] TitaniumKit 0x0000000102c65eb8 TiBindingRunLoopEnqueue + 68
[ERROR] TitaniumKit 0x0000000102c46984 TiBindingEventProcess + 792
[ERROR] TitaniumKit 0x0000000102c600f8 -[Invocation KrollContext:] + 84
[ERROR] TitaniumKit 0x0000000102c60160 -[KrollContext queue:] + 84
[ERROR] TitaniumKit 0x0000000102c65eb8 TiBindingRunLoopEnqueue + 68
[ERROR] TitaniumKit 0x0000000102c64bc4 -[TiProxy fireEvent:withObject:propagate:reportSuccess:errorCode:message:] + 184
[ERROR] TitaniumKit 0x0000000102c4c854 -[TiViewProxy fireEvent:withObject:propagate:reportSuccess:errorCode:message:] + 204
[ERROR] TitaniumKit 0x0000000102c41208 -[TiUIView touchEnded:withEvent:] + 84
[ERROR] UIKitCore 0x000000018df229c0 F1A8BD61-9CF2-3054-B622-CB63D6CEB4CB + 2107840
[ERROR] UIKitCore 0x000000018df22364 F1A8BD61-9CF2-3054-B622-CB63D6CEB4CB + 2106212
[ERROR] UIKitCore 0x000000018df215e4 F1A8BD61-9CF2-3054-B622-CB63D6CEB4CB + 2102756,

Can you help me?

*** -[NSURL initFileURLWithPath:]: nil string parameter

Unable to use recognition based on an existing file. Whatever the file URL is set to I get:

*** -[NSURL initFileURLWithPath:]: nil string parameter

Have Tried:

  • /samples/mpthreetest.mp3
  • the nativePath to it
  • a remote HTTP file

all fail with the same error.

Example App Crash

Before making changes to anything the example app crashes on iOS 10.3.3. Not sure what is going wrong.

Issue is solved. Had to do with improper trap.xml configurations. Code is working as expected.

Unable to relaunch ti.speech

When i stop the speech recognition ("live audio" in the demo project) with TiSpeech.stopRecognition();
and i restart the speech recognition with TiSpeech.startRecognition for the second time, I get this error:
[ERROR] An error occurred with speech recognition
[ERROR] Error Domain=kAFAssistantErrorDomain Code=209 "(null)"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.