@reactxnative/react-native-voice 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/build.gradle +56 -0
- package/android/src/main/AndroidManifest.xml +4 -0
- package/android/src/main/java/com/reactxnative/reactnativevoice/ReactNativeVoiceModule.kt +90 -0
- package/android/src/main/java/com/reactxnative/reactnativevoice/ReactNativeVoicePackage.kt +16 -0
- package/lib/commonjs/index.js +42 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/module/index.js +34 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/typescript/react-native.config.d.ts +10 -0
- package/lib/typescript/react-native.config.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +7 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/package.json +67 -0
- package/src/index.tsx +44 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
buildscript {
|
|
2
|
+
if (project == rootProject) {
|
|
3
|
+
repositories {
|
|
4
|
+
google()
|
|
5
|
+
mavenCentral()
|
|
6
|
+
}
|
|
7
|
+
dependencies {
|
|
8
|
+
classpath("com.android.tools.build:gradle:7.3.1")
|
|
9
|
+
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.22")
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
apply plugin: 'com.android.library'
|
|
15
|
+
apply plugin: 'kotlin-android'
|
|
16
|
+
|
|
17
|
+
def getExtOrDefault(name) {
|
|
18
|
+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['ReactNativeVoice_' + name]
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
def getExtOrIntegerDefault(name) {
|
|
22
|
+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties['ReactNativeVoice_' + name]).toInteger()
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
android {
|
|
26
|
+
compileSdkVersion getExtOrIntegerDefault('compileSdkVersion') ?: 33
|
|
27
|
+
|
|
28
|
+
defaultConfig {
|
|
29
|
+
minSdkVersion getExtOrIntegerDefault('minSdkVersion') ?: 21
|
|
30
|
+
targetSdkVersion getExtOrIntegerDefault('targetSdkVersion') ?: 33
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
namespace 'com.reactxnative.reactnativevoice'
|
|
34
|
+
|
|
35
|
+
buildTypes {
|
|
36
|
+
release {
|
|
37
|
+
minifyEnabled false
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
sourceSets {
|
|
42
|
+
main {
|
|
43
|
+
java.srcDirs += ['src/main/java']
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
repositories {
|
|
49
|
+
mavenCentral()
|
|
50
|
+
google()
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
dependencies {
|
|
54
|
+
implementation 'com.facebook.react:react-native:+'
|
|
55
|
+
implementation "org.jetbrains.kotlin:kotlin-stdlib:1.7.22"
|
|
56
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
package com.reactxnative.reactnativevoice
|
|
2
|
+
|
|
3
|
+
import android.content.Intent
|
|
4
|
+
import android.os.Bundle
|
|
5
|
+
import android.speech.RecognitionListener
|
|
6
|
+
import android.speech.RecognizerIntent
|
|
7
|
+
import android.speech.SpeechRecognizer
|
|
8
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
9
|
+
import com.facebook.react.bridge.ReactContextBaseJavaModule
|
|
10
|
+
import com.facebook.react.bridge.ReactMethod
|
|
11
|
+
import com.facebook.react.modules.core.DeviceEventManagerModule
|
|
12
|
+
|
|
13
|
+
class ReactNativeVoiceModule(private val reactContext: ReactApplicationContext) :
|
|
14
|
+
ReactContextBaseJavaModule(reactContext) {
|
|
15
|
+
|
|
16
|
+
private var speechRecognizer: SpeechRecognizer? = null
|
|
17
|
+
|
|
18
|
+
override fun getName(): String = "CustomVoiceRecognizer"
|
|
19
|
+
|
|
20
|
+
private fun sendEvent(eventName: String, params: com.facebook.react.bridge.WritableMap) {
|
|
21
|
+
reactContext
|
|
22
|
+
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
|
|
23
|
+
.emit(eventName, params)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
private val recognitionListener = object : RecognitionListener {
|
|
27
|
+
override fun onReadyForSpeech(params: Bundle?) {}
|
|
28
|
+
override fun onBeginningOfSpeech() {}
|
|
29
|
+
override fun onRmsChanged(rmsdB: Float) {}
|
|
30
|
+
override fun onBufferReceived(buffer: ByteArray?) {}
|
|
31
|
+
override fun onEndOfSpeech() {}
|
|
32
|
+
override fun onPartialResults(partialResults: Bundle?) {}
|
|
33
|
+
override fun onEvent(eventType: Int, params: Bundle?) {}
|
|
34
|
+
|
|
35
|
+
override fun onResults(results: Bundle?) {
|
|
36
|
+
val matches = results?.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION)
|
|
37
|
+
if (!matches.isNullOrEmpty()) {
|
|
38
|
+
val map = com.facebook.react.bridge.Arguments.createMap()
|
|
39
|
+
map.putString("value", matches[0])
|
|
40
|
+
sendEvent("onSpeechResults", map)
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
override fun onError(error: Int) {
|
|
45
|
+
val map = com.facebook.react.bridge.Arguments.createMap()
|
|
46
|
+
map.putInt("error", error)
|
|
47
|
+
sendEvent("onSpeechError", map)
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
@ReactMethod
|
|
52
|
+
fun startListening() {
|
|
53
|
+
reactContext.runOnUiQueueThread {
|
|
54
|
+
if (speechRecognizer == null) {
|
|
55
|
+
speechRecognizer = SpeechRecognizer.createSpeechRecognizer(reactContext)
|
|
56
|
+
speechRecognizer?.setRecognitionListener(recognitionListener)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
val intent = Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH).apply {
|
|
60
|
+
putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM)
|
|
61
|
+
putExtra(RecognizerIntent.EXTRA_LANGUAGE, "hi-IN")
|
|
62
|
+
putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 5)
|
|
63
|
+
putExtra(RecognizerIntent.EXTRA_PARTIAL_RESULTS, false)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
speechRecognizer?.startListening(intent)
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
@ReactMethod
|
|
71
|
+
fun stopListening() {
|
|
72
|
+
reactContext.runOnUiQueueThread {
|
|
73
|
+
speechRecognizer?.stopListening()
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
@ReactMethod
|
|
78
|
+
fun destroy() {
|
|
79
|
+
reactContext.runOnUiQueueThread {
|
|
80
|
+
speechRecognizer?.destroy()
|
|
81
|
+
speechRecognizer = null
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
@ReactMethod
|
|
86
|
+
fun addListener(eventName: String) {}
|
|
87
|
+
|
|
88
|
+
@ReactMethod
|
|
89
|
+
fun removeListeners(count: Int) {}
|
|
90
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
package com.reactxnative.reactnativevoice
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.ReactPackage
|
|
4
|
+
import com.facebook.react.bridge.NativeModule
|
|
5
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
6
|
+
import com.facebook.react.uimanager.ViewManager
|
|
7
|
+
|
|
8
|
+
class ReactNativeVoicePackage : ReactPackage {
|
|
9
|
+
override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
|
|
10
|
+
return listOf(ReactNativeVoiceModule(reactContext))
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
|
|
14
|
+
return emptyList()
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.addSpeechErrorListener = addSpeechErrorListener;
|
|
7
|
+
exports.addSpeechResultsListener = addSpeechResultsListener;
|
|
8
|
+
exports.destroy = destroy;
|
|
9
|
+
exports.startListening = startListening;
|
|
10
|
+
exports.stopListening = stopListening;
|
|
11
|
+
var _reactNative = require("react-native");
|
|
12
|
+
const LINKING_ERROR = `The package '@reactxnative/react-native-voice' doesn't seem to be linked. Make sure: \n\n` + _reactNative.Platform.select({
|
|
13
|
+
ios: "- You have run 'pod install'\n",
|
|
14
|
+
default: ''
|
|
15
|
+
}) + '- You rebuilt the app after installing the package\n' + '- You are not using Expo Go\n';
|
|
16
|
+
const CustomVoiceRecognizer = _reactNative.NativeModules.CustomVoiceRecognizer ? _reactNative.NativeModules.CustomVoiceRecognizer : new Proxy({}, {
|
|
17
|
+
get() {
|
|
18
|
+
throw new Error(LINKING_ERROR);
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
function startListening() {
|
|
22
|
+
if (_reactNative.Platform.OS === 'android') {
|
|
23
|
+
CustomVoiceRecognizer.startListening();
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function stopListening() {
|
|
27
|
+
if (_reactNative.Platform.OS === 'android') {
|
|
28
|
+
CustomVoiceRecognizer.stopListening();
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function destroy() {
|
|
32
|
+
if (_reactNative.Platform.OS === 'android') {
|
|
33
|
+
CustomVoiceRecognizer.destroy();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
function addSpeechResultsListener(callback) {
|
|
37
|
+
return _reactNative.DeviceEventEmitter.addListener('onSpeechResults', event => callback(event.value));
|
|
38
|
+
}
|
|
39
|
+
function addSpeechErrorListener(callback) {
|
|
40
|
+
return _reactNative.DeviceEventEmitter.addListener('onSpeechError', event => callback(event.error));
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_reactNative","require","LINKING_ERROR","Platform","select","ios","default","CustomVoiceRecognizer","NativeModules","Proxy","get","Error","startListening","OS","stopListening","destroy","addSpeechResultsListener","callback","DeviceEventEmitter","addListener","event","value","addSpeechErrorListener","error"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAEA,MAAMC,aAAa,GACjB,2FAA2F,GAC3FC,qBAAQ,CAACC,MAAM,CAAC;EAAEC,GAAG,EAAE,gCAAgC;EAAEC,OAAO,EAAE;AAAG,CAAC,CAAC,GACvE,sDAAsD,GACtD,+BAA+B;AAEjC,MAAMC,qBAAqB,GAAGC,0BAAa,CAACD,qBAAqB,GAC7DC,0BAAa,CAACD,qBAAqB,GACnC,IAAIE,KAAK,CACP,CAAC,CAAC,EACF;EACEC,GAAGA,CAAA,EAAG;IACJ,MAAM,IAAIC,KAAK,CAACT,aAAa,CAAC;EAChC;AACF,CACF,CAAC;AAEE,SAASU,cAAcA,CAAA,EAAS;EACrC,IAAIT,qBAAQ,CAACU,EAAE,KAAK,SAAS,EAAE;IAC7BN,qBAAqB,CAACK,cAAc,CAAC,CAAC;EACxC;AACF;AAEO,SAASE,aAAaA,CAAA,EAAS;EACpC,IAAIX,qBAAQ,CAACU,EAAE,KAAK,SAAS,EAAE;IAC7BN,qBAAqB,CAACO,aAAa,CAAC,CAAC;EACvC;AACF;AAEO,SAASC,OAAOA,CAAA,EAAS;EAC9B,IAAIZ,qBAAQ,CAACU,EAAE,KAAK,SAAS,EAAE;IAC7BN,qBAAqB,CAACQ,OAAO,CAAC,CAAC;EACjC;AACF;AAEO,SAASC,wBAAwBA,CAACC,QAAiC,EAAuB;EAC/F,OAAOC,+BAAkB,CAACC,WAAW,CAAC,iBAAiB,EAAGC,KAAK,IAAKH,QAAQ,CAACG,KAAK,CAACC,KAAK,CAAC,CAAC;AAC5F;AAEO,SAASC,sBAAsBA,CAACL,QAAiC,EAAuB;EAC7F,OAAOC,+BAAkB,CAACC,WAAW,CAAC,eAAe,EAAGC,KAAK,IAAKH,QAAQ,CAACG,KAAK,CAACG,KAAK,CAAC,CAAC;AAC1F","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { NativeModules, DeviceEventEmitter, Platform } from 'react-native';
|
|
4
|
+
const LINKING_ERROR = `The package '@reactxnative/react-native-voice' doesn't seem to be linked. Make sure: \n\n` + Platform.select({
|
|
5
|
+
ios: "- You have run 'pod install'\n",
|
|
6
|
+
default: ''
|
|
7
|
+
}) + '- You rebuilt the app after installing the package\n' + '- You are not using Expo Go\n';
|
|
8
|
+
const CustomVoiceRecognizer = NativeModules.CustomVoiceRecognizer ? NativeModules.CustomVoiceRecognizer : new Proxy({}, {
|
|
9
|
+
get() {
|
|
10
|
+
throw new Error(LINKING_ERROR);
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
export function startListening() {
|
|
14
|
+
if (Platform.OS === 'android') {
|
|
15
|
+
CustomVoiceRecognizer.startListening();
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export function stopListening() {
|
|
19
|
+
if (Platform.OS === 'android') {
|
|
20
|
+
CustomVoiceRecognizer.stopListening();
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export function destroy() {
|
|
24
|
+
if (Platform.OS === 'android') {
|
|
25
|
+
CustomVoiceRecognizer.destroy();
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
export function addSpeechResultsListener(callback) {
|
|
29
|
+
return DeviceEventEmitter.addListener('onSpeechResults', event => callback(event.value));
|
|
30
|
+
}
|
|
31
|
+
export function addSpeechErrorListener(callback) {
|
|
32
|
+
return DeviceEventEmitter.addListener('onSpeechError', event => callback(event.error));
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["NativeModules","DeviceEventEmitter","Platform","LINKING_ERROR","select","ios","default","CustomVoiceRecognizer","Proxy","get","Error","startListening","OS","stopListening","destroy","addSpeechResultsListener","callback","addListener","event","value","addSpeechErrorListener","error"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,SAASA,aAAa,EAAEC,kBAAkB,EAAuBC,QAAQ,QAAQ,cAAc;AAE/F,MAAMC,aAAa,GACjB,2FAA2F,GAC3FD,QAAQ,CAACE,MAAM,CAAC;EAAEC,GAAG,EAAE,gCAAgC;EAAEC,OAAO,EAAE;AAAG,CAAC,CAAC,GACvE,sDAAsD,GACtD,+BAA+B;AAEjC,MAAMC,qBAAqB,GAAGP,aAAa,CAACO,qBAAqB,GAC7DP,aAAa,CAACO,qBAAqB,GACnC,IAAIC,KAAK,CACP,CAAC,CAAC,EACF;EACEC,GAAGA,CAAA,EAAG;IACJ,MAAM,IAAIC,KAAK,CAACP,aAAa,CAAC;EAChC;AACF,CACF,CAAC;AAEL,OAAO,SAASQ,cAAcA,CAAA,EAAS;EACrC,IAAIT,QAAQ,CAACU,EAAE,KAAK,SAAS,EAAE;IAC7BL,qBAAqB,CAACI,cAAc,CAAC,CAAC;EACxC;AACF;AAEA,OAAO,SAASE,aAAaA,CAAA,EAAS;EACpC,IAAIX,QAAQ,CAACU,EAAE,KAAK,SAAS,EAAE;IAC7BL,qBAAqB,CAACM,aAAa,CAAC,CAAC;EACvC;AACF;AAEA,OAAO,SAASC,OAAOA,CAAA,EAAS;EAC9B,IAAIZ,QAAQ,CAACU,EAAE,KAAK,SAAS,EAAE;IAC7BL,qBAAqB,CAACO,OAAO,CAAC,CAAC;EACjC;AACF;AAEA,OAAO,SAASC,wBAAwBA,CAACC,QAAiC,EAAuB;EAC/F,OAAOf,kBAAkB,CAACgB,WAAW,CAAC,iBAAiB,EAAGC,KAAK,IAAKF,QAAQ,CAACE,KAAK,CAACC,KAAK,CAAC,CAAC;AAC5F;AAEA,OAAO,SAASC,sBAAsBA,CAACJ,QAAiC,EAAuB;EAC7F,OAAOf,kBAAkB,CAACgB,WAAW,CAAC,eAAe,EAAGC,KAAK,IAAKF,QAAQ,CAACE,KAAK,CAACG,KAAK,CAAC,CAAC;AAC1F","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react-native.config.d.ts","sourceRoot":"","sources":["../../react-native.config.js"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { EmitterSubscription } from 'react-native';
|
|
2
|
+
export declare function startListening(): void;
|
|
3
|
+
export declare function stopListening(): void;
|
|
4
|
+
export declare function destroy(): void;
|
|
5
|
+
export declare function addSpeechResultsListener(callback: (value: string) => void): EmitterSubscription;
|
|
6
|
+
export declare function addSpeechErrorListener(callback: (error: number) => void): EmitterSubscription;
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAqC,mBAAmB,EAAY,MAAM,cAAc,CAAC;AAmBhG,wBAAgB,cAAc,IAAI,IAAI,CAIrC;AAED,wBAAgB,aAAa,IAAI,IAAI,CAIpC;AAED,wBAAgB,OAAO,IAAI,IAAI,CAI9B;AAED,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,GAAG,mBAAmB,CAE/F;AAED,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,GAAG,mBAAmB,CAE7F"}
|
package/package.json
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@reactxnative/react-native-voice",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "A custom voice recognizer for React Native Android",
|
|
5
|
+
"main": "lib/commonjs/index.js",
|
|
6
|
+
"module": "lib/module/index.js",
|
|
7
|
+
"types": "lib/typescript/src/index.d.ts",
|
|
8
|
+
"react-native": "src/index.tsx",
|
|
9
|
+
"source": "src/index.tsx",
|
|
10
|
+
"files": [
|
|
11
|
+
"src",
|
|
12
|
+
"lib",
|
|
13
|
+
"android",
|
|
14
|
+
"ios",
|
|
15
|
+
"cpp",
|
|
16
|
+
"*.podspec",
|
|
17
|
+
"!ios/build",
|
|
18
|
+
"!android/build",
|
|
19
|
+
"!android/gradle",
|
|
20
|
+
"!android/gradlew",
|
|
21
|
+
"!android/gradlew.bat",
|
|
22
|
+
"!android/local.properties",
|
|
23
|
+
"!**/__tests__",
|
|
24
|
+
"!**/__fixtures__",
|
|
25
|
+
"!**/__mocks__",
|
|
26
|
+
"!**/.*"
|
|
27
|
+
],
|
|
28
|
+
"scripts": {
|
|
29
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
30
|
+
"build": "bob build",
|
|
31
|
+
"prepare": "bob build"
|
|
32
|
+
},
|
|
33
|
+
"keywords": [
|
|
34
|
+
"react-native",
|
|
35
|
+
"ios",
|
|
36
|
+
"android"
|
|
37
|
+
],
|
|
38
|
+
"repository": {
|
|
39
|
+
"type": "git",
|
|
40
|
+
"url": "git+https://github.com/rahulsingh/react-native-voice.git"
|
|
41
|
+
},
|
|
42
|
+
"author": "Rahul Singh <rahulreactnative1995@example.com>",
|
|
43
|
+
"license": "MIT",
|
|
44
|
+
"peerDependencies": {
|
|
45
|
+
"react": "*",
|
|
46
|
+
"react-native": "*"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"react-native-builder-bob": "^0.30.2",
|
|
50
|
+
"@types/react": "^19.2.0",
|
|
51
|
+
"typescript": "^5.2.2"
|
|
52
|
+
},
|
|
53
|
+
"react-native-builder-bob": {
|
|
54
|
+
"source": "src",
|
|
55
|
+
"output": "lib",
|
|
56
|
+
"targets": [
|
|
57
|
+
"commonjs",
|
|
58
|
+
"module",
|
|
59
|
+
[
|
|
60
|
+
"typescript",
|
|
61
|
+
{
|
|
62
|
+
"project": "tsconfig.build.json"
|
|
63
|
+
}
|
|
64
|
+
]
|
|
65
|
+
]
|
|
66
|
+
}
|
|
67
|
+
}
|
package/src/index.tsx
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { NativeModules, DeviceEventEmitter, EmitterSubscription, Platform } from 'react-native';
|
|
2
|
+
|
|
3
|
+
const LINKING_ERROR =
|
|
4
|
+
`The package '@reactxnative/react-native-voice' doesn't seem to be linked. Make sure: \n\n` +
|
|
5
|
+
Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
|
|
6
|
+
'- You rebuilt the app after installing the package\n' +
|
|
7
|
+
'- You are not using Expo Go\n';
|
|
8
|
+
|
|
9
|
+
const CustomVoiceRecognizer = NativeModules.CustomVoiceRecognizer
|
|
10
|
+
? NativeModules.CustomVoiceRecognizer
|
|
11
|
+
: new Proxy(
|
|
12
|
+
{},
|
|
13
|
+
{
|
|
14
|
+
get() {
|
|
15
|
+
throw new Error(LINKING_ERROR);
|
|
16
|
+
},
|
|
17
|
+
}
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
export function startListening(): void {
|
|
21
|
+
if (Platform.OS === 'android') {
|
|
22
|
+
CustomVoiceRecognizer.startListening();
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function stopListening(): void {
|
|
27
|
+
if (Platform.OS === 'android') {
|
|
28
|
+
CustomVoiceRecognizer.stopListening();
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function destroy(): void {
|
|
33
|
+
if (Platform.OS === 'android') {
|
|
34
|
+
CustomVoiceRecognizer.destroy();
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function addSpeechResultsListener(callback: (value: string) => void): EmitterSubscription {
|
|
39
|
+
return DeviceEventEmitter.addListener('onSpeechResults', (event) => callback(event.value));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function addSpeechErrorListener(callback: (error: number) => void): EmitterSubscription {
|
|
43
|
+
return DeviceEventEmitter.addListener('onSpeechError', (event) => callback(event.error));
|
|
44
|
+
}
|