# react-native-kdspeech

> React Native Speech

Latest version **0.0.5** (published 2018-01-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-native-kdspeech
pnpm add react-native-kdspeech
yarn add react-native-kdspeech
bun add react-native-kdspeech
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.5 |
| Published | 2018-01-23 |
| First published | 2018-01-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | xpbtmusic |
| Maintainers | xpbtmusic |
| Keywords | react-native, android, Speech |

## Links

- npm: https://www.npmjs.com/package/react-native-kdspeech
- Repository: https://github.com/xpbtmusic/kdSpeech
- Homepage: https://github.com/xpbtmusic/kdSpeech#readme
- Issues: https://github.com/xpbtmusic/kdSpeech/issues
- npm.io page: https://npm.io/package/react-native-kdspeech

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 0.0.5 (latest) — 2018-01-23
- 0.0.3 — 2018-01-23
- 0.0.4 — 2018-01-23
- 0.0.2 — 2018-01-02
- 0.0.1 — 2018-01-02

## README

1.使用

语音识别


Installation:
```
 npm install --save react-native-kdspeech
```
替换自己 app  android/app/res/values/appid 去官网申请appid

AndroidManifest.xml添加权限
```
    <uses-permission android:name="android.permission.RECORD_AUDIO"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.INTERNET" />
```
```javascript
import React, {PureComponent} from 'react'
import {
    View,
    Text,
    Platform,
    Button,
    DeviceEventEmitter,
    PermissionsAndroid
} from 'react-native'
//import SpeechModule from './SpeechModule'
import {SpeechModule} from 'react-native-kdspeech'

class Demo extends PureComponent {


    constructor(props: Object) {
        super(props)

        this.state = {
            resultText: '',
            permission: PermissionsAndroid.PERMISSIONS.RECORD_AUDIO,
        }
    }

    componentWillMount() {

        SpeechModule.addRecResultCallBack(this.onRecognizeResult)

    }


    componentWillUnMount() {
        SpeechModule.removeRecCallBack(this.onRecognizeResult);
    }

    onRecognizeResult = (e) => {
        console.log('result text: ' + e);
        this.setState({
            resultText: e,
        });

    }


    onPressButton(title) {


    }


    _requestPermission = async () => {
        let result = await PermissionsAndroid.request(
            this.state.permission
        );
        if (result === PermissionsAndroid.RESULTS.GRANTED||result) {
            SpeechModule.startSpeech();

        } else {
            this._requestPermission();
        }
    }

    onButtonClick() {
        if (Platform.OS === 'android') {
            this._checkPermission();
        }
    }

    _checkPermission = async () => {
        let result = await PermissionsAndroid.check(this.state.permission);
        if (result === PermissionsAndroid.RESULTS.GRANTED||result) {
            SpeechModule.startSpeech();
        } else {
            this._requestPermission();
        }
    }

    onButtonClick_() {
        if (Platform.OS === 'android') {
            SpeechModule.stopSpeech();
        }
    }


    render() {
        return (

            <View style={{flex: 1, backgroundColor: 'white'}}>

                <Text style={{flex: 1, backgroundColor: 'white',marginTop:10}}>
                    识别结果:{this.state.resultText}
                </Text>
                <View style={{flex: 1,marginTop:60}}>
                    <Button title="开启语音识别" onPress={this.onButtonClick.bind(this)}></Button>
                    <View style={{height:10}}></View>
                    <Button title="停止语音识别" color="#841584" onPress={this.onButtonClick_.bind(this)}></Button>
                </View>
            </View>
        );
    }

}

export default Demo;
```

---
_Source: https://npm.io/package/react-native-kdspeech · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
