Coder Social home page Coder Social logo

douglowder / react-native-voice Goto Github PK

View Code? Open in Web Editor NEW

This project forked from react-native-voice/voice

0.0 2.0 0.0 295 KB

:microphone: React Native Voice Recognition library for iOS and Android (Online and Offline Support)

License: MIT License

JavaScript 25.66% Python 4.55% Java 36.83% Objective-C 32.95%

react-native-voice's Introduction

npm deps

React Native Voice

A speech-to-text library for React Native.

npm i react-native-voice --save

Table of contents

Linking

Manually or automatically link the NativeModule

react-native link react-native-voice

Manually Link Android

  • In android/setting.gradle
...
include ':react-native-voice', ':app'
project(':react-native-voice').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-voice/android')
  • In android/app/build.gradle
...
dependencies {
    ...
    compile project(':react-native-voice')
}
  • In MainApplication.java
import android.app.Application;
import com.facebook.react.ReactApplication;
import com.facebook.react.ReactPackage;
...
import com.wenkesj.voice.VoicePackage; // <------ Add this!
...

public class MainActivity extends Activity implements ReactApplication {
...
    @Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
        new MainReactPackage(),
        new VoicePackage() // <------ Add this!
        );
    }
}

Manually Link iOS

  • Drag the Voice.xcodeproj from the react-native-voice/ios folder to the Libraries group on Xcode in your poject. Manual linking

  • Click on your main project file (the one that represents the .xcodeproj) select Build Phases and drag the static library, lib.Voice.a, from the Libraries/Voice.xcodeproj/Products folder to Link Binary With Libraries

Usage

Full example for Android and iOS.

Example

import Voice from 'react-native-voice';
import React, {Component} from 'react';

class VoiceTest extends Component {
  constructor(props) {
    Voice.onSpeechStart = this.onSpeechStartHandler.bind(this);
    Voice.onSpeechEnd = this.onSpeechEndHandler.bind(this);
    Voice.onSpeechResults = this.onSpeechResultsHandler.bind(this);
  }
  onStartButtonPress(e){
    Voice.start('en-US');
  }
  ...
}

API

Static access to the Voice API.

All methods now return a new Promise for async/await compatibility.

Method Name Description Platform
Voice.isAvailable() Checks whether a speech recognition service is available on the system. Android, iOS
Voice.start(locale) Starts listening for speech for a specific locale. Returns null if no error occurs. Android, iOS
Voice.stop() Stops listening for speech. Returns null if no error occurs. Android, iOS
Voice.cancel() Cancels the speech recognition. Returns null if no error occurs. Android, iOS
Voice.destroy() Destroys the current SpeechRecognizer instance. Returns null if no error occurs. Android, iOS
Voice.removeAllListeners() Cleans/nullifies overridden Voice static methods. Android, iOS
Voice.isRecognizing() Return if the SpeechRecognizer is recognizing. Android, iOS

Events

Callbacks that are invoked when a native event emitted.

Event Name Description Event Platform
Voice.onSpeechStart(event) Invoked when .start() is called without error. { error: false } Android, iOS
Voice.onSpeechRecognized(event) Invoked when speech is recognized. { error: false } Android, iOS
Voice.onSpeechEnd(event) Invoked when SpeechRecognizer stops recognition. { error: false } Android, iOS
Voice.onSpeechError(event) Invoked when an error occurs. { error: Description of error as string } Android, iOS
Voice.onSpeechResults(event) Invoked when SpeechRecognizer is finished recognizing. { value: [..., 'Speech recognized'] } Android, iOS
Voice.onSpeechPartialResults(event) Invoked when any results are computed. { value: [..., 'Partial speech recognized'] } Android, iOS
Voice.onSpeechVolumeChanged(event) Invoked when pitch that is recognized changed. { value: pitch in dB } Android

Permissions

Arguably the most important part.

Android

While the included VoiceTest app works without explicit permissions checks and requests, it may be necessary to add a permission request for RECORD_AUDIO for some configurations. Since Android M (6.0), user need to grant permission at runtime (and not during app installation). By default, calling the startSpeech method will invoke RECORD AUDIO permission popup to the user. This can be disabled by passing REQUEST_PERMISSIONS_AUTO: true in the options argument.

iOS

Need to include permissions for NSMicrophoneUsageDescription and NSSpeechRecognitionUsageDescription inside Info.plist for iOS. See the included VoiceTest for how to handle these cases.

<dict>
  ...
  <key>NSMicrophoneUsageDescription</key>
  <string>Description of why you require the use of the microphone</string>
  <key>NSSpeechRecognitionUsageDescription</key>
  <string>Description of why you require the use of the speech recognition</string>
  ...
</dict>

Please see the documentation provided by ReactNative for this: PermissionsAndroid

Contibutors

  • @asafron
  • @BrendanFDMoore
  • @brudny
  • @chitezh
  • @ifsnow
  • @jamsch
  • @misino
  • @Noitidart
  • @ohtangza & @hayanmind
  • @rudiedev6
  • @tdonia
  • @wenkesj

react-native-voice's People

Contributors

wenkesj avatar brendanfdmoore avatar ohtangza avatar misino avatar noitidart avatar tdonia avatar rudiedev6 avatar asafron avatar austinkelleher avatar chitezh avatar yujif avatar brudny avatar ifsnow avatar jamsch avatar

Watchers

James Cloos avatar Douglas Lowder avatar

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.