Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ local.properties

# Visual Studio Code
.vscode/
# Package Library
*.tgz
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ npx pod-install
- [Permissions](#permissions)
- [Android](#android)
- [iOS](#ios)
- [Local Development](#local-development)
- [Contributors](#contributors)

<h2 align="center">Linking</h2>
Expand Down Expand Up @@ -247,6 +248,10 @@ Please see the documentation provided by ReactNative for this: [PermissionsAndro
[npm-url]: https://npmjs.com/package/@react-native-voice/voice
[circle-ci-badge]: https://img.shields.io/circleci/project/github/react-native-voice/voice/master.svg?style=flat-square

<h2 align="center">Local Development</h2>

For a detailed guide on how to test local changes in another React Native project, please see the [Local Development Guide](./docs/LOCAL_DEVELOPMENT.md).

<h2 align="center">Contributors</h2>

- @asafron
Expand All @@ -255,9 +260,10 @@ Please see the documentation provided by ReactNative for this: [PermissionsAndro
- @chitezh
- @ifsnow
- @jamsch
- @jsnavarroc
- @misino
- @Noitidart
- @ohtangza & @hayanmind
- @rudiedev6
- @tdonia
- @wenkesj
- @wenkesj
34 changes: 23 additions & 11 deletions android/src/main/java/com/wenkesj/voice/Voice.kt
Original file line number Diff line number Diff line change
Expand Up @@ -307,21 +307,33 @@ class Voice (context:ReactApplicationContext):RecognitionListener {
Log.d("ASR", "onError() - $errorMessage")
}

override fun onResults(results: Bundle?) {
val arr = Arguments.createArray()

val matches = results!!.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION)
if (matches != null) {
for (result in matches) {
arr.pushString(result)
override fun onResults(results: Bundle?) {
val arr = Arguments.createArray()

try {
val matches = results?.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION)

if (!matches.isNullOrEmpty()) {
for (i in 0 until matches.size) {
arr.pushString(matches[i])
}
} else {
Log.w("ASR", "onResults(): matches is null or empty")
arr.pushString("") // aún puedes notificar algo vacío
}
val event = Arguments.createMap()
event.putArray("value", arr)
sendEvent("onSpeechResults", event)
Log.d("ASR", "onResults()")

} catch (e: Exception) {
Log.e("ASR", "onResults(): Exception - ${e.message}")
arr.pushString("") // fallback si falla todo
}

val event = Arguments.createMap()
event.putArray("value", arr)
sendEvent("onSpeechResults", event)
Log.d("ASR", "onResults()")
}


override fun onPartialResults(partialResults: Bundle?) {
val arr = Arguments.createArray()

Expand Down
84 changes: 84 additions & 0 deletions docs/LOCAL_DEVELOPMENT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# Local Development Guide

This guide explains how to test local changes to this library (`@react-native-voice/voice`) in another React Native project without needing to publish the changes to npm.

The `file:` method in `package.json` may not work correctly for libraries with native code because it doesn't run the necessary build steps. The following process ensures that the library is compiled and packaged in the same way as if it were downloaded from npm.

## Local Linking Process

Follow these steps each time you make a change to the library and want to test it in your application.

### Step 1: Compile the Library

The library's source code is written in TypeScript (`src/`) and needs to be compiled to JavaScript (`dist/`).

1. Open a terminal in the root directory of this library (`voice`).
2. Run the following command to compile the code:

```bash
yarn prepare
```

This will run the TypeScript compiler (`tsc`) and create the `dist/` folder with the JavaScript code required for React Native to work.

### Step 2: Package the Library

Next, create a compressed package (`.tgz`) of the library, which is the same format that npm uses to distribute packages.

1. In the same directory, run:

```bash
npm pack
```

2. This command will create a file with a name similar to `react-native-voice-voice-x.x.x.tgz`. This file contains all the library's files, ready to be installed.

### Step 3: Move the Package to Your Project

Copy the `.tgz` file you just created to the root of the project where you want to test the library.

```bash
# Example: Copy from the 'voice' library to your 'MyApp' project
# Make sure to replace the paths with your own
cp /path/to/voice/react-native-voice-voice-x.x.x.tgz /path/to/MyApp/
```

### Step 4: Install the Local Package in Your Project

Now, navigate to your project's folder and install the library from the `.tgz` file.

1. Open a terminal in the root directory of your project (e.g., `MyApp`).
2. **Important:** If you already have a version of the library installed, uninstall it first to avoid conflicts:

```bash
yarn remove @react-native-voice/voice
```

3. Install the library from the local file:

```bash
# Replace the filename with the one you generated
yarn add file:./react-native-voice-voice-x.x.x.tgz
```

This will install the library into your `node_modules` and add the correct reference in your `package.json`.

### Step 5: Rebuild Your Application

Because this library contains native code (Kotlin/Swift), it is **crucial** that you rebuild your application so that the changes are compiled and included in your app.

1. In your project's directory, run:

```bash
# For Android
npx react-native run-android

# For iOS
npx react-native run-ios
```

That's it! Your application will now be using the local version of the library with all your changes.

---

**Note:** You will need to repeat this process (compile, pack, copy, install, and rebuild) every time you make new changes to the library that you want to test.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"react": "18.3.1",
"react-native": "^0.76.2",
"semantic-release": "^24.2.0",
"typescript": "5.6.3"
"typescript": "^5.8.3"
},
"keywords": [
"android",
Expand Down
2 changes: 1 addition & 1 deletion plugin/tsconfig.tsbuildinfo
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"root":["./src/withvoice.ts"],"version":"5.6.3"}
{"root":["./src/withvoice.ts"],"version":"5.8.3"}
53 changes: 43 additions & 10 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1263,7 +1263,20 @@
"@babel/parser" "^7.27.0"
"@babel/types" "^7.27.0"

"@babel/traverse--for-generate-function-map@npm:@babel/traverse@^7.25.3", "@babel/traverse@^7.25.3", "@babel/traverse@^7.25.9":
"@babel/traverse--for-generate-function-map@npm:@babel/traverse@^7.25.3":
version "7.25.9"
resolved "https://registry.npmjs.org/@babel/traverse/-/traverse-7.25.9.tgz"
integrity sha512-ZCuvfwOwlz/bawvAuvcj8rrithP2/N55Tzz342AkTvq4qaWbGfmCk/tKhNaV2cthijKrPAA8SRJV5WWe7IBMJw==
dependencies:
"@babel/code-frame" "^7.25.9"
"@babel/generator" "^7.25.9"
"@babel/parser" "^7.25.9"
"@babel/template" "^7.25.9"
"@babel/types" "^7.25.9"
debug "^4.3.1"
globals "^11.1.0"

"@babel/traverse@^7.25.3", "@babel/traverse@^7.25.9":
version "7.25.9"
resolved "https://registry.npmjs.org/@babel/traverse/-/traverse-7.25.9.tgz"
integrity sha512-ZCuvfwOwlz/bawvAuvcj8rrithP2/N55Tzz342AkTvq4qaWbGfmCk/tKhNaV2cthijKrPAA8SRJV5WWe7IBMJw==
Expand Down Expand Up @@ -9662,7 +9675,16 @@ string-natural-compare@^3.0.1:
resolved "https://registry.npmjs.org/string-natural-compare/-/string-natural-compare-3.0.1.tgz"
integrity sha512-n3sPwynL1nwKi3WJ6AIsClwBMa0zTi54fn2oLU6ndfTSIO05xaznjSf15PcBZU6FNWbmN5Q6cxT4V5hGvB4taw==

"string-width-cjs@npm:string-width@^4.2.0", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
"string-width-cjs@npm:string-width@^4.2.0":
version "4.2.3"
resolved "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
dependencies:
emoji-regex "^8.0.0"
is-fullwidth-code-point "^3.0.0"
strip-ansi "^6.0.1"

string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
version "4.2.3"
resolved "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
Expand Down Expand Up @@ -9792,7 +9814,14 @@ string_decoder@~1.1.1:
dependencies:
safe-buffer "~5.1.0"

"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1:
"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
version "6.0.1"
resolved "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
dependencies:
ansi-regex "^5.0.1"

strip-ansi@^6.0.0, strip-ansi@^6.0.1:
version "6.0.1"
resolved "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
Expand Down Expand Up @@ -10269,12 +10298,7 @@ typed-array-length@^1.0.7:
possible-typed-array-names "^1.0.0"
reflect.getprototypeof "^1.0.6"

[email protected]:
version "5.6.3"
resolved "https://registry.npmjs.org/typescript/-/typescript-5.6.3.tgz"
integrity sha512-hjcS1mhfuyi4WW8IWtjP7brDrG2cuDZukyrYrSauoXGNgx0S7zceP07adYkJycEr56BOUTNPzbInooiN3fn1qw==

typescript@^5.1.3:
typescript@^5.1.3, typescript@^5.8.3:
version "5.8.3"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.8.3.tgz#92f8a3e5e3cf497356f4178c34cd65a7f5e8440e"
integrity sha512-p1diW6TqL9L07nNxvRMM7hMMw4c5XOo/1ibL4aAIGmSAt9slTE1Xgw5KWuof2uTOvCg9BY7ZRi+GaF+7sfgPeQ==
Expand Down Expand Up @@ -10654,7 +10678,16 @@ wordwrap@^1.0.0:
resolved "https://registry.npmjs.org/wordwrap/-/wordwrap-1.0.0.tgz"
integrity sha512-gvVzJFlPycKc5dZN4yPkP8w7Dc37BtP1yczEneOb4uq34pXZcvrtRTmWV8W+Ume+XCxKgbjM+nevkyFPMybd4Q==

"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0:
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0":
version "7.0.0"
resolved "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz"
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
dependencies:
ansi-styles "^4.0.0"
string-width "^4.1.0"
strip-ansi "^6.0.0"

wrap-ansi@^7.0.0:
version "7.0.0"
resolved "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz"
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
Expand Down