react-native-rn-speech-to-text 0.1.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/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 faheem-weft
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ of this software and associated documentation files (the "Software"), to deal
6
+ in the Software without restriction, including without limitation the rights
7
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the Software is
9
+ furnished to do so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all
12
+ copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,37 @@
1
+ # react-native-speech-to-text-android
2
+
3
+ convert voice to text
4
+
5
+ ## Installation
6
+
7
+
8
+ ```sh
9
+ npm install react-native-speech-to-text-android
10
+ ```
11
+
12
+
13
+ ## Usage
14
+
15
+
16
+ ```js
17
+ import { multiply } from 'react-native-speech-to-text-android';
18
+
19
+ // ...
20
+
21
+ const result = multiply(3, 7);
22
+ ```
23
+
24
+
25
+ ## Contributing
26
+
27
+ - [Development workflow](CONTRIBUTING.md#development-workflow)
28
+ - [Sending a pull request](CONTRIBUTING.md#sending-a-pull-request)
29
+ - [Code of conduct](CODE_OF_CONDUCT.md)
30
+
31
+ ## License
32
+
33
+ MIT
34
+
35
+ ---
36
+
37
+ Made with [create-react-native-library](https://github.com/callstack/react-native-builder-bob)
@@ -0,0 +1,20 @@
1
+ require "json"
2
+
3
+ package = JSON.parse(File.read(File.join(__dir__, "package.json")))
4
+
5
+ Pod::Spec.new do |s|
6
+ s.name = "SpeechToTextAndroid"
7
+ s.version = package["version"]
8
+ s.summary = package["description"]
9
+ s.homepage = package["homepage"]
10
+ s.license = package["license"]
11
+ s.authors = package["author"]
12
+
13
+ s.platforms = { :ios => min_ios_version_supported }
14
+ s.source = { :git => "https://www.npmjs.com/~faheem_katta.git", :tag => "#{s.version}" }
15
+
16
+ s.source_files = "ios/**/*.{h,m,mm,swift,cpp}"
17
+ s.private_header_files = "ios/**/*.h"
18
+
19
+ install_modules_dependencies(s)
20
+ end
@@ -0,0 +1,67 @@
1
+ buildscript {
2
+ ext.SpeechToTextAndroid = [
3
+ kotlinVersion: "2.0.21",
4
+ minSdkVersion: 24,
5
+ compileSdkVersion: 36,
6
+ targetSdkVersion: 36
7
+ ]
8
+
9
+ ext.getExtOrDefault = { prop ->
10
+ if (rootProject.ext.has(prop)) {
11
+ return rootProject.ext.get(prop)
12
+ }
13
+
14
+ return SpeechToTextAndroid[prop]
15
+ }
16
+
17
+ repositories {
18
+ google()
19
+ mavenCentral()
20
+ }
21
+
22
+ dependencies {
23
+ classpath "com.android.tools.build:gradle:8.7.2"
24
+ // noinspection DifferentKotlinGradleVersion
25
+ classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${getExtOrDefault('kotlinVersion')}"
26
+ }
27
+ }
28
+
29
+
30
+ apply plugin: "com.android.library"
31
+ apply plugin: "kotlin-android"
32
+
33
+ apply plugin: "com.facebook.react"
34
+
35
+ android {
36
+ namespace "com.speechtotextandroid"
37
+
38
+ compileSdkVersion getExtOrDefault("compileSdkVersion")
39
+
40
+ defaultConfig {
41
+ minSdkVersion getExtOrDefault("minSdkVersion")
42
+ targetSdkVersion getExtOrDefault("targetSdkVersion")
43
+ }
44
+
45
+ buildFeatures {
46
+ buildConfig true
47
+ }
48
+
49
+ buildTypes {
50
+ release {
51
+ minifyEnabled false
52
+ }
53
+ }
54
+
55
+ lint {
56
+ disable "GradleCompatible"
57
+ }
58
+
59
+ compileOptions {
60
+ sourceCompatibility JavaVersion.VERSION_1_8
61
+ targetCompatibility JavaVersion.VERSION_1_8
62
+ }
63
+ }
64
+
65
+ dependencies {
66
+ implementation "com.facebook.react:react-android"
67
+ }
@@ -0,0 +1,3 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android">
2
+ <uses-permission android:name="android.permission.RECORD_AUDIO" />
3
+ </manifest>
@@ -0,0 +1,56 @@
1
+ package com.speechtotextandroid
2
+
3
+ import android.os.Bundle
4
+ import android.speech.RecognitionListener
5
+ import android.speech.SpeechRecognizer
6
+ import com.facebook.react.bridge.ReactApplicationContext
7
+ import com.facebook.react.modules.core.DeviceEventManagerModule
8
+
9
+ class SpeechRecognitionListener(
10
+ private val reactContext: ReactApplicationContext
11
+ ) : RecognitionListener {
12
+
13
+ private fun sendEvent(event: String, data: String?) {
14
+ if (!reactContext.hasActiveCatalystInstance()) return
15
+
16
+ reactContext
17
+ .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
18
+ .emit(event, data)
19
+ }
20
+
21
+ override fun onReadyForSpeech(params: Bundle?) {
22
+ sendEvent("onSpeechStart", "Listening...")
23
+ }
24
+
25
+ override fun onBeginningOfSpeech() {
26
+ sendEvent("onSpeechBeginning", null)
27
+ }
28
+
29
+ override fun onRmsChanged(rmsdB: Float) {}
30
+
31
+ override fun onBufferReceived(buffer: ByteArray?) {}
32
+
33
+ override fun onEndOfSpeech() {
34
+ sendEvent("onSpeechEnd", null)
35
+ }
36
+
37
+ override fun onError(error: Int) {
38
+ sendEvent("onSpeechError", error.toString())
39
+ }
40
+
41
+ override fun onResults(results: Bundle?) {
42
+ val matches =
43
+ results?.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION)
44
+
45
+ sendEvent("onSpeechResult", matches?.get(0))
46
+ }
47
+
48
+ override fun onPartialResults(partialResults: Bundle?) {
49
+ val matches =
50
+ partialResults?.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION)
51
+
52
+ sendEvent("onSpeechPartialResult", matches?.get(0))
53
+ }
54
+
55
+ override fun onEvent(eventType: Int, params: Bundle?) {}
56
+ }
@@ -0,0 +1,95 @@
1
+ package com.speechtotextandroid
2
+
3
+ import android.content.Intent
4
+ import android.os.Handler
5
+ import android.os.Looper
6
+ import android.speech.RecognizerIntent
7
+ import android.speech.SpeechRecognizer
8
+ import com.facebook.react.bridge.*
9
+ import com.facebook.react.modules.core.DeviceEventManagerModule
10
+
11
+ class SpeechToTextAndroidModule(
12
+ private val reactContext: ReactApplicationContext
13
+ ) : ReactContextBaseJavaModule(reactContext) {
14
+
15
+ private var speechRecognizer: SpeechRecognizer? = null
16
+ private val mainHandler = Handler(Looper.getMainLooper())
17
+ private var isListening = false
18
+
19
+ override fun getName(): String = "SpeechToTextAndroid"
20
+
21
+ private fun sendEvent(event: String, data: String?) {
22
+ if (!reactContext.hasActiveCatalystInstance()) return
23
+
24
+ reactContext
25
+ .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
26
+ .emit(event, data)
27
+ }
28
+
29
+ private fun createRecognizerIfNeeded() {
30
+ if (speechRecognizer == null) {
31
+ speechRecognizer = SpeechRecognizer.createSpeechRecognizer(reactContext)
32
+
33
+ speechRecognizer?.setRecognitionListener(
34
+ object : android.speech.RecognitionListener {
35
+
36
+ override fun onReadyForSpeech(params: android.os.Bundle?) {
37
+ sendEvent("onSpeechStart", "Listening...")
38
+ }
39
+
40
+ override fun onResults(results: android.os.Bundle?) {
41
+ val matches =
42
+ results?.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION)
43
+
44
+ sendEvent("onSpeechResult", matches?.get(0))
45
+ }
46
+
47
+ override fun onError(error: Int) {
48
+ sendEvent("onSpeechError", error.toString())
49
+ }
50
+
51
+ override fun onBeginningOfSpeech() {}
52
+ override fun onRmsChanged(rmsdB: Float) {}
53
+ override fun onBufferReceived(buffer: ByteArray?) {}
54
+ override fun onEndOfSpeech() {}
55
+ override fun onPartialResults(partialResults: android.os.Bundle?) {}
56
+ override fun onEvent(eventType: Int, params: android.os.Bundle?) {}
57
+ }
58
+ )
59
+ }
60
+ }
61
+
62
+ @ReactMethod
63
+ fun startListening() {
64
+ mainHandler.post {
65
+
66
+ if (!SpeechRecognizer.isRecognitionAvailable(reactContext)) return@post
67
+ if (isListening) return@post
68
+
69
+ createRecognizerIfNeeded()
70
+
71
+ val intent = Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH)
72
+ intent.putExtra(
73
+ RecognizerIntent.EXTRA_LANGUAGE_MODEL,
74
+ RecognizerIntent.LANGUAGE_MODEL_FREE_FORM
75
+ )
76
+ intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "en-US")
77
+
78
+ speechRecognizer?.startListening(intent)
79
+ isListening = true
80
+ }
81
+ }
82
+
83
+ @ReactMethod
84
+ fun stopListening() {
85
+ mainHandler.post {
86
+ speechRecognizer?.stopListening()
87
+ isListening = false
88
+ }
89
+ }
90
+
91
+ override fun onCatalystInstanceDestroy() {
92
+ speechRecognizer?.destroy()
93
+ speechRecognizer = null
94
+ }
95
+ }
@@ -0,0 +1,20 @@
1
+ package com.speechtotextandroid
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 SpeechToTextAndroidPackage : ReactPackage {
9
+ override fun createNativeModules(
10
+ reactContext: ReactApplicationContext
11
+ ): List<NativeModule> {
12
+ return listOf(SpeechToTextAndroidModule(reactContext))
13
+ }
14
+
15
+ override fun createViewManagers(
16
+ reactContext: ReactApplicationContext
17
+ ): List<ViewManager<*, *>> {
18
+ return emptyList()
19
+ }
20
+ }
@@ -0,0 +1,5 @@
1
+ #import <SpeechToTextAndroidSpec/SpeechToTextAndroidSpec.h>
2
+
3
+ @interface SpeechToTextAndroid : NSObject <NativeSpeechToTextAndroidSpec>
4
+
5
+ @end
@@ -0,0 +1,21 @@
1
+ #import "SpeechToTextAndroid.h"
2
+
3
+ @implementation SpeechToTextAndroid
4
+ - (NSNumber *)multiply:(double)a b:(double)b {
5
+ NSNumber *result = @(a * b);
6
+
7
+ return result;
8
+ }
9
+
10
+ - (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
11
+ (const facebook::react::ObjCTurboModule::InitParams &)params
12
+ {
13
+ return std::make_shared<facebook::react::NativeSpeechToTextAndroidSpecJSI>(params);
14
+ }
15
+
16
+ + (NSString *)moduleName
17
+ {
18
+ return @"SpeechToTextAndroid";
19
+ }
20
+
21
+ @end
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ import { TurboModuleRegistry } from 'react-native';
4
+ export default TurboModuleRegistry.getEnforcing('SpeechToTextAndroid');
5
+ //# sourceMappingURL=NativeSpeechToTextAndroid.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["TurboModuleRegistry","getEnforcing"],"sourceRoot":"../../src","sources":["NativeSpeechToTextAndroid.ts"],"mappings":";;AAAA,SAASA,mBAAmB,QAA0B,cAAc;AAMpE,eAAeA,mBAAmB,CAACC,YAAY,CAAO,qBAAqB,CAAC","ignoreList":[]}
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+
3
+ import { NativeModules, NativeEventEmitter } from 'react-native';
4
+ const NativeModule = NativeModules.SpeechToTextAndroid;
5
+ if (!NativeModule) {
6
+ throw new Error('SpeechToTextAndroid native module is not linked properly.');
7
+ }
8
+ const eventEmitter = new NativeEventEmitter(NativeModules.SpeechToTextAndroid);
9
+ export const startListening = () => {
10
+ NativeModule.startListening();
11
+ };
12
+ export const stopListening = () => {
13
+ NativeModule.stopListening();
14
+ };
15
+ export const addSpeechResultListener = callback => eventEmitter.addListener('onSpeechResult', data => callback(String(data)));
16
+ export const addSpeechErrorListener = callback => eventEmitter.addListener('onSpeechError', data => callback(String(data)));
17
+ export const addSpeechStartListener = callback => eventEmitter.addListener('onSpeechStart', data => callback(String(data)));
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["NativeModules","NativeEventEmitter","NativeModule","SpeechToTextAndroid","Error","eventEmitter","startListening","stopListening","addSpeechResultListener","callback","addListener","data","String","addSpeechErrorListener","addSpeechStartListener"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;AAAA,SAASA,aAAa,EAAEC,kBAAkB,QAAQ,cAAc;AAYhE,MAAMC,YAAY,GAChBF,aAAa,CAACG,mBAAsD;AAEtE,IAAI,CAACD,YAAY,EAAE;EACjB,MAAM,IAAIE,KAAK,CAAC,2DAA2D,CAAC;AAC9E;AAEA,MAAMC,YAAY,GAAG,IAAIJ,kBAAkB,CAACD,aAAa,CAACG,mBAAmB,CAAC;AAE9E,OAAO,MAAMG,cAAc,GAAGA,CAAA,KAAY;EACxCJ,YAAY,CAACI,cAAc,CAAC,CAAC;AAC/B,CAAC;AAED,OAAO,MAAMC,aAAa,GAAGA,CAAA,KAAY;EACvCL,YAAY,CAACK,aAAa,CAAC,CAAC;AAC9B,CAAC;AAED,OAAO,MAAMC,uBAAuB,GAClCC,QAAgC,IAEhCJ,YAAY,CAACK,WAAW,CAAC,gBAAgB,EAAGC,IAAa,IACvDF,QAAQ,CAACG,MAAM,CAACD,IAAI,CAAC,CACvB,CAAC;AAEH,OAAO,MAAME,sBAAsB,GACjCJ,QAAiC,IAEjCJ,YAAY,CAACK,WAAW,CAAC,eAAe,EAAGC,IAAa,IACtDF,QAAQ,CAACG,MAAM,CAACD,IAAI,CAAC,CACvB,CAAC;AAEH,OAAO,MAAMG,sBAAsB,GACjCL,QAA+B,IAE/BJ,YAAY,CAACK,WAAW,CAAC,eAAe,EAAGC,IAAa,IACtDF,QAAQ,CAACG,MAAM,CAACD,IAAI,CAAC,CACvB,CAAC","ignoreList":[]}
@@ -0,0 +1 @@
1
+ {"type":"module"}
@@ -0,0 +1 @@
1
+ {"type":"module"}
@@ -0,0 +1,7 @@
1
+ import { type TurboModule } from 'react-native';
2
+ export interface Spec extends TurboModule {
3
+ multiply(a: number, b: number): number;
4
+ }
5
+ declare const _default: Spec;
6
+ export default _default;
7
+ //# sourceMappingURL=NativeSpeechToTextAndroid.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NativeSpeechToTextAndroid.d.ts","sourceRoot":"","sources":["../../../src/NativeSpeechToTextAndroid.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAErE,MAAM,WAAW,IAAK,SAAQ,WAAW;IACvC,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CACxC;;AAED,wBAA6E"}
@@ -0,0 +1,7 @@
1
+ import type { EmitterSubscription } from 'react-native';
2
+ export declare const startListening: () => void;
3
+ export declare const stopListening: () => void;
4
+ export declare const addSpeechResultListener: (callback: (text: string) => void) => EmitterSubscription;
5
+ export declare const addSpeechErrorListener: (callback: (error: string) => void) => EmitterSubscription;
6
+ export declare const addSpeechStartListener: (callback: (msg: string) => void) => EmitterSubscription;
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAoBxD,eAAO,MAAM,cAAc,QAAO,IAEjC,CAAC;AAEF,eAAO,MAAM,aAAa,QAAO,IAEhC,CAAC;AAEF,eAAO,MAAM,uBAAuB,GAClC,UAAU,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,KAC/B,mBAGA,CAAC;AAEJ,eAAO,MAAM,sBAAsB,GACjC,UAAU,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,KAChC,mBAGA,CAAC;AAEJ,eAAO,MAAM,sBAAsB,GACjC,UAAU,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,KAC9B,mBAGA,CAAC"}
package/package.json ADDED
@@ -0,0 +1,169 @@
1
+ {
2
+ "name": "react-native-rn-speech-to-text",
3
+ "version": "0.1.0",
4
+ "description": "convert voice to text",
5
+ "main": "./lib/module/index.js",
6
+ "types": "./lib/typescript/src/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "source": "./src/index.tsx",
10
+ "types": "./lib/typescript/src/index.d.ts",
11
+ "default": "./lib/module/index.js"
12
+ },
13
+ "./package.json": "./package.json"
14
+ },
15
+ "files": [
16
+ "src",
17
+ "lib",
18
+ "android",
19
+ "ios",
20
+ "cpp",
21
+ "*.podspec",
22
+ "react-native.config.js",
23
+ "!ios/build",
24
+ "!android/build",
25
+ "!android/gradle",
26
+ "!android/gradlew",
27
+ "!android/gradlew.bat",
28
+ "!android/local.properties",
29
+ "!**/__tests__",
30
+ "!**/__fixtures__",
31
+ "!**/__mocks__",
32
+ "!**/.*"
33
+ ],
34
+ "scripts": {
35
+ "example": "yarn workspace react-native-speech-to-text-android-example",
36
+ "clean": "del-cli android/build example/android/build example/android/app/build example/ios/build lib",
37
+ "prepare": "bob build",
38
+ "typecheck": "tsc",
39
+ "lint": "eslint \"**/*.{js,ts,tsx}\"",
40
+ "test": "jest",
41
+ "release": "release-it --only-version"
42
+ },
43
+ "keywords": [
44
+ "react-native",
45
+ "ios",
46
+ "android"
47
+ ],
48
+ "repository": {
49
+ "type": "git",
50
+ "url": "git+https://www.npmjs.com/~faheem_katta.git"
51
+ },
52
+ "author": "faheem-weft <faheem.tfora@gmail.com> (https://www.npmjs.com/~faheem_katta)",
53
+ "license": "MIT",
54
+ "bugs": {
55
+ "url": "https://www.npmjs.com/~faheem_katta/issues"
56
+ },
57
+ "homepage": "https://www.npmjs.com/~faheem_katta#readme",
58
+ "publishConfig": {
59
+ "registry": "https://registry.npmjs.org/"
60
+ },
61
+ "devDependencies": {
62
+ "@commitlint/config-conventional": "^19.8.1",
63
+ "@eslint/compat": "^1.3.2",
64
+ "@eslint/eslintrc": "^3.3.1",
65
+ "@eslint/js": "^9.35.0",
66
+ "@react-native/babel-preset": "0.83.0",
67
+ "@react-native/eslint-config": "0.83.0",
68
+ "@release-it/conventional-changelog": "^10.0.1",
69
+ "@types/jest": "^29.5.14",
70
+ "@types/react": "^19.2.0",
71
+ "commitlint": "^19.8.1",
72
+ "del-cli": "^6.0.0",
73
+ "eslint": "^9.35.0",
74
+ "eslint-config-prettier": "^10.1.8",
75
+ "eslint-plugin-prettier": "^5.5.4",
76
+ "jest": "^29.7.0",
77
+ "lefthook": "^2.0.3",
78
+ "prettier": "^2.8.8",
79
+ "react": "19.2.0",
80
+ "react-native": "0.83.0",
81
+ "react-native-builder-bob": "^0.40.13",
82
+ "release-it": "^19.0.4",
83
+ "turbo": "^2.5.6",
84
+ "typescript": "^5.9.2"
85
+ },
86
+ "peerDependencies": {
87
+ "react": "*",
88
+ "react-native": "*"
89
+ },
90
+ "workspaces": [
91
+ "example"
92
+ ],
93
+ "packageManager": "yarn@4.11.0",
94
+ "react-native-builder-bob": {
95
+ "source": "src",
96
+ "output": "lib",
97
+ "targets": [
98
+ [
99
+ "module",
100
+ {
101
+ "esm": true
102
+ }
103
+ ],
104
+ [
105
+ "typescript",
106
+ {
107
+ "project": "tsconfig.build.json"
108
+ }
109
+ ]
110
+ ]
111
+ },
112
+ "codegenConfig": {
113
+ "name": "SpeechToTextAndroidSpec",
114
+ "type": "modules",
115
+ "jsSrcsDir": "src",
116
+ "android": {
117
+ "javaPackageName": "com.speechtotextandroid"
118
+ }
119
+ },
120
+ "prettier": {
121
+ "quoteProps": "consistent",
122
+ "singleQuote": true,
123
+ "tabWidth": 2,
124
+ "trailingComma": "es5",
125
+ "useTabs": false
126
+ },
127
+ "jest": {
128
+ "preset": "react-native",
129
+ "modulePathIgnorePatterns": [
130
+ "<rootDir>/example/node_modules",
131
+ "<rootDir>/lib/"
132
+ ]
133
+ },
134
+ "commitlint": {
135
+ "extends": [
136
+ "@commitlint/config-conventional"
137
+ ]
138
+ },
139
+ "release-it": {
140
+ "git": {
141
+ "commitMessage": "chore: release ${version}",
142
+ "tagName": "v${version}"
143
+ },
144
+ "npm": {
145
+ "publish": true
146
+ },
147
+ "github": {
148
+ "release": true
149
+ },
150
+ "plugins": {
151
+ "@release-it/conventional-changelog": {
152
+ "preset": {
153
+ "name": "angular"
154
+ }
155
+ }
156
+ }
157
+ },
158
+ "create-react-native-library": {
159
+ "type": "turbo-module",
160
+ "languages": "kotlin-objc",
161
+ "tools": [
162
+ "eslint",
163
+ "jest",
164
+ "lefthook",
165
+ "release-it"
166
+ ],
167
+ "version": "0.57.2"
168
+ }
169
+ }
@@ -0,0 +1,7 @@
1
+ import { TurboModuleRegistry, type TurboModule } from 'react-native';
2
+
3
+ export interface Spec extends TurboModule {
4
+ multiply(a: number, b: number): number;
5
+ }
6
+
7
+ export default TurboModuleRegistry.getEnforcing<Spec>('SpeechToTextAndroid');
package/src/index.ts ADDED
@@ -0,0 +1,49 @@
1
+ import { NativeModules, NativeEventEmitter } from 'react-native';
2
+ import type { EmitterSubscription } from 'react-native';
3
+
4
+ interface SpeechToTextAndroidNativeModule {
5
+ startListening(): void;
6
+ stopListening(): void;
7
+
8
+ // Required for NativeEventEmitter typing
9
+ addListener(eventName: string): void;
10
+ removeListeners(count: number): void;
11
+ }
12
+
13
+ const NativeModule =
14
+ NativeModules.SpeechToTextAndroid as SpeechToTextAndroidNativeModule;
15
+
16
+ if (!NativeModule) {
17
+ throw new Error('SpeechToTextAndroid native module is not linked properly.');
18
+ }
19
+
20
+ const eventEmitter = new NativeEventEmitter(NativeModules.SpeechToTextAndroid);
21
+
22
+ export const startListening = (): void => {
23
+ NativeModule.startListening();
24
+ };
25
+
26
+ export const stopListening = (): void => {
27
+ NativeModule.stopListening();
28
+ };
29
+
30
+ export const addSpeechResultListener = (
31
+ callback: (text: string) => void
32
+ ): EmitterSubscription =>
33
+ eventEmitter.addListener('onSpeechResult', (data: unknown) =>
34
+ callback(String(data))
35
+ );
36
+
37
+ export const addSpeechErrorListener = (
38
+ callback: (error: string) => void
39
+ ): EmitterSubscription =>
40
+ eventEmitter.addListener('onSpeechError', (data: unknown) =>
41
+ callback(String(data))
42
+ );
43
+
44
+ export const addSpeechStartListener = (
45
+ callback: (msg: string) => void
46
+ ): EmitterSubscription =>
47
+ eventEmitter.addListener('onSpeechStart', (data: unknown) =>
48
+ callback(String(data))
49
+ );