npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-native-speech-recognizer

v1.0.4

Published

react-native-speech-recognizer

Downloads

131

Readme

中文文档(Usage in Chinese)

react-native-speech-recognizer

A speech-recongintion library for React Native(Support Chinese and English),Chinese is dependent on baidu API.

install

npm install react-native-speech-recognizer --save

Linking

Automatic

react-native link react-native-speech-recognizer

Manual

Make alterations to the following files in your project:

Android

  1. Add following lines to android/settings.gradle
...
include ':react-native-speech-recognizer'
project(':react-native-speech-recognizer').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-speech-recognizer/android')
...
  1. Add the compile line to dependencies in android/app/build.gradle
...
dependencies {
    ...
    compile project(':react-native-speech-recognizer')
    ...
}
  1. Add import and link the package in android/app/src/.../MainApplication.java
import port com.zhangxiaoduo.rnsr.SpeechRecognitionPackage;  // <--- add import

public class MainApplication extends Application implements ReactApplication {
    // ...
    @Override
    protected List<ReactPackage> getPackages() {
        return Arrays.<ReactPackage>asList(
            new MainReactPackage(),
            // ...
            new SpeechRecognitionPackage()                      // <--- add package
        );
    }

IOS

  1. In the XCode's "Project navigator", right click on your project's Libraries folder ➜ Add Files to <...>
  2. Go to node_modulesreact-native-speech-recognizerios ➜ select SpeechRecognition.xcodeproj
  3. Add SpeechRecognition.a to Build Phases -> Link Binary With Libraries

Permission

Android

  1. Add permission in android/app/src/main/AndroidManifest.xml
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
  1. Since Android M(6.0), user need to grant permission at runtime.
    Add following lines to android/app/src/.../MainActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    checkAndRequestPermissions();
}
private void checkAndRequestPermissions() {
      int sdkVersion = Build.VERSION.SDK_INT;
      if (sdkVersion >= Build.VERSION_CODES.M) {
          if (ActivityCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO)
                  != PackageManager.PERMISSION_GRANTED
                  || ActivityCompat.checkSelfPermission(this, Manifest.permission.INTERNET)
                  != PackageManager.PERMISSION_GRANTED
                  || ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_NETWORK_STATE)
                  != PackageManager.PERMISSION_GRANTED
                  || ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_PHONE_STATE)
                  != PackageManager.PERMISSION_GRANTED) {
              ActivityCompat.requestPermissions(this,
                      new String[]{Manifest.permission.RECORD_AUDIO,
                              Manifest.permission.INTERNET,
                              Manifest.permission.ACCESS_NETWORK_STATE,
                              Manifest.permission.READ_PHONE_STATE
                      },
                      1);
          }
      }
  }
  1. Add your APP_ID,API_KEY,SECRET_KEY in android/app/src/main/AndroidManifest.xml
    Click here to get your own APP_ID,API_KEY,SECRET_KEY
<application
    ...
    <meta-data
        android:name="com.baidu.speech.APP_ID"
        android:value="10337431" />
    <meta-data
        android:name="com.baidu.speech.API_KEY"
        android:value="Ptivienw5Qx75uRnKalq7Eq2" />
   <meta-data
       android:name="com.baidu.speech.SECRET_KEY"
       android:value="bd5c689721bfa3530330c677e87303a6" />
    ...
</application>

IOS

Add permission to your Info.plist

<dict>
  ...
  <key>NSSpeechRecognitionUsageDescription</key>
  <string>Your usage description here</string>
  <key>NSMicrophoneUsageDescription</key>
  <string>Your usage description here</string>
  ...
</dict>

Usage

import SpeechRecognizer from 'react-native-speech-recognizer';

...

componentWillMount() {
    this.state = {
        result: '';
    };
    SpeechRecognizer.init(result=>this.setState({result}));
}

...

componentWillUnmount() {
    SpeechRecognizer.end();
}

...

render() {
//SpeechRecognizer.start('zh'); 'zh' or 'eng',default:'zh'
...
    <TouchableOpacity 
        onPressIn={()=> SpeechRecognizer.start('zh')} 
        onPressOut={()=> SpeechRecognizer.finish()}>
        ...
    </TouchableOpacity>
    <Text>{this.state.result}</Text>
...
}