├── .circleci └── config.yml ├── .editorconfig ├── .gitattributes ├── .gitignore ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── Transcription.xcworkspace ├── contents.xcworkspacedata └── xcshareddata │ └── IDEWorkspaceChecks.plist ├── android ├── .project ├── .settings │ └── org.eclipse.buildship.core.prefs ├── build.gradle ├── gradle.properties ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── src │ └── main │ ├── AndroidManifest.xml │ └── java │ └── com │ └── reactnativetranscription │ ├── AdtsHeaderBuilder.java │ ├── AudioRecordThread.kt │ ├── FileTranscriptionModule.kt │ ├── OnAudioRecordListener.kt │ ├── RecordingItem.kt │ ├── TranscriptionModule.kt │ ├── TranscriptionPackage.kt │ └── WavHeaderFunctions.java ├── babel.config.js ├── example ├── android │ ├── .project │ ├── .settings │ │ └── org.eclipse.buildship.core.prefs │ ├── app │ │ ├── build.gradle │ │ ├── debug.keystore │ │ ├── proguard-rules.pro │ │ └── src │ │ │ ├── debug │ │ │ ├── AndroidManifest.xml │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── example │ │ │ │ └── reactnativetranscription │ │ │ │ └── ReactNativeFlipper.java │ │ │ └── main │ │ │ ├── AndroidManifest.xml │ │ │ ├── java │ │ │ └── com │ │ │ │ └── example │ │ │ │ └── reactnativetranscription │ │ │ │ ├── MainActivity.java │ │ │ │ └── MainApplication.java │ │ │ └── res │ │ │ ├── mipmap-hdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-mdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xhdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxhdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxxhdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ │ └── values │ │ │ ├── strings.xml │ │ │ └── styles.xml │ ├── build.gradle │ ├── gradle.properties │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ └── settings.gradle ├── app.json ├── babel.config.js ├── index.tsx ├── ios │ ├── File.swift │ ├── Podfile │ ├── Podfile.lock │ ├── TranscriptionExample-Bridging-Header.h │ ├── TranscriptionExample.xcodeproj │ │ ├── project.pbxproj │ │ └── xcshareddata │ │ │ └── xcschemes │ │ │ └── TranscriptionExample.xcscheme │ ├── TranscriptionExample.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ └── TranscriptionExample │ │ ├── AppDelegate.h │ │ ├── AppDelegate.m │ │ ├── Base.lproj │ │ └── LaunchScreen.xib │ │ ├── Images.xcassets │ │ ├── AppIcon.appiconset │ │ │ └── Contents.json │ │ └── Contents.json │ │ ├── Info.plist │ │ └── main.m ├── metro.config.js ├── package-lock.json ├── package.json ├── src │ └── App.js └── yarn.lock ├── ios ├── AudioContext.swift ├── Frameworks │ └── deepspeech_ios.framework │ │ ├── Headers │ │ ├── deepspeech_ios-Swift.h │ │ └── deepspeech_ios.h │ │ ├── Info.plist │ │ ├── Modules │ │ ├── deepspeech_ios.swiftmodule │ │ │ ├── Project │ │ │ │ ├── arm64-apple-ios.swiftsourceinfo │ │ │ │ └── arm64.swiftsourceinfo │ │ │ ├── arm64-apple-ios.swiftdoc │ │ │ ├── arm64-apple-ios.swiftinterface │ │ │ ├── arm64-apple-ios.swiftmodule │ │ │ ├── arm64.swiftdoc │ │ │ ├── arm64.swiftinterface │ │ │ └── arm64.swiftmodule │ │ └── module.modulemap │ │ ├── PrivateHeaders │ │ └── deepspeech.h │ │ ├── _CodeSignature │ │ └── CodeResources │ │ └── deepspeech_ios ├── Transcription-Bridging-Header.h ├── Transcription.m ├── Transcription.swift ├── Transcription.xcodeproj │ └── project.pbxproj └── Transcription.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ └── IDEWorkspaceChecks.plist ├── package.json ├── react-native-transcription.podspec ├── src ├── __tests__ │ └── index.test.tsx └── index.tsx ├── tsconfig.json └── yarn.lock /.circleci/config.yml: -------------------------------------------------------------------------------- 1 | version: 2.1 2 | 3 | executors: 4 | default: 5 | docker: 6 | - image: circleci/node:10 7 | working_directory: ~/project 8 | 9 | commands: 10 | attach_project: 11 | steps: 12 | - attach_workspace: 13 | at: ~/project 14 | 15 | jobs: 16 | install-dependencies: 17 | executor: default 18 | steps: 19 | - checkout 20 | - attach_project 21 | - restore_cache: 22 | keys: 23 | - dependencies-{{ checksum "package.json" }} 24 | - dependencies- 25 | - restore_cache: 26 | keys: 27 | - dependencies-example-{{ checksum "example/package.json" }} 28 | - dependencies-example- 29 | - run: 30 | name: Install dependencies 31 | command: | 32 | yarn install --cwd example --frozen-lockfile 33 | yarn install --frozen-lockfile 34 | - save_cache: 35 | key: dependencies-{{ checksum "package.json" }} 36 | paths: node_modules 37 | - save_cache: 38 | key: dependencies-example-{{ checksum "example/package.json" }} 39 | paths: example/node_modules 40 | - persist_to_workspace: 41 | root: . 42 | paths: . 43 | 44 | lint: 45 | executor: default 46 | steps: 47 | - attach_project 48 | - run: 49 | name: Lint files 50 | command: | 51 | yarn lint 52 | 53 | typescript: 54 | executor: default 55 | steps: 56 | - attach_project 57 | - run: 58 | name: Typecheck files 59 | command: | 60 | yarn typescript 61 | 62 | unit-tests: 63 | executor: default 64 | steps: 65 | - attach_project 66 | - run: 67 | name: Run unit tests 68 | command: | 69 | yarn test --coverage 70 | - store_artifacts: 71 | path: coverage 72 | destination: coverage 73 | 74 | build-package: 75 | executor: default 76 | steps: 77 | - attach_project 78 | - run: 79 | name: Build package 80 | command: | 81 | yarn prepare 82 | 83 | workflows: 84 | build-and-test: 85 | jobs: 86 | - install-dependencies 87 | - lint: 88 | requires: 89 | - install-dependencies 90 | - typescript: 91 | requires: 92 | - install-dependencies 93 | - unit-tests: 94 | requires: 95 | - install-dependencies 96 | - build-package: 97 | requires: 98 | - install-dependencies 99 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig helps developers define and maintain consistent 2 | # coding styles between different editors and IDEs 3 | # editorconfig.org 4 | 5 | root = true 6 | 7 | [*] 8 | 9 | indent_style = space 10 | indent_size = 2 11 | 12 | end_of_line = lf 13 | charset = utf-8 14 | trim_trailing_whitespace = true 15 | insert_final_newline = true 16 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.pbxproj -text 2 | # specific for windows script files 3 | *.bat text eol=crlf -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # OSX 2 | # 3 | .DS_Store 4 | 5 | # XDE 6 | .expo/ 7 | 8 | # VSCode 9 | .vscode/ 10 | jsconfig.json 11 | 12 | # Xcode 13 | # 14 | build/ 15 | *.pbxuser 16 | !default.pbxuser 17 | *.mode1v3 18 | !default.mode1v3 19 | *.mode2v3 20 | !default.mode2v3 21 | *.perspectivev3 22 | !default.perspectivev3 23 | xcuserdata 24 | *.xccheckout 25 | *.moved-aside 26 | DerivedData 27 | *.hmap 28 | *.ipa 29 | *.xcuserstate 30 | project.xcworkspace 31 | 32 | # Android/IJ 33 | # 34 | .idea 35 | .gradle 36 | local.properties 37 | android.iml 38 | 39 | # Cocoapods 40 | # 41 | example/ios/Pods 42 | 43 | # node.js 44 | # 45 | node_modules/ 46 | npm-debug.log 47 | yarn-debug.log 48 | yarn-error.log 49 | 50 | # BUCK 51 | buck-out/ 52 | \.buckd/ 53 | android/app/libs 54 | android/keystores/debug.keystore 55 | 56 | # Expo 57 | .expo/* 58 | 59 | # generated by bob 60 | lib/ 61 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | We want this community to be friendly and respectful to each other. Please follow it in all your interactions with the project. 4 | 5 | ## Development workflow 6 | 7 | To get started with the project, run `yarn bootstrap` in the root directory to install the required dependencies for each package: 8 | 9 | ```sh 10 | yarn bootstrap 11 | ``` 12 | 13 | While developing, you can run the [example app](/example/) to test your changes. 14 | 15 | To start the packager: 16 | 17 | ```sh 18 | yarn example start 19 | ``` 20 | 21 | To run the example app on Android: 22 | 23 | ```sh 24 | yarn example android 25 | ``` 26 | 27 | To run the example app on iOS: 28 | 29 | ```sh 30 | yarn example ios 31 | ``` 32 | 33 | Make sure your code passes TypeScript and ESLint. Run the following to verify: 34 | 35 | ```sh 36 | yarn typescript 37 | yarn lint 38 | ``` 39 | 40 | To fix formatting errors, run the following: 41 | 42 | ```sh 43 | yarn lint --fix 44 | ``` 45 | 46 | Remember to add tests for your change if possible. Run the unit tests by: 47 | 48 | ```sh 49 | yarn test 50 | ``` 51 | 52 | To edit the Objective-C files, open `example/ios/TranscriptionExample.xcworkspace` in XCode and find the source files at `Pods > Development Pods > react-native-transcription`. 53 | 54 | To edit the Kotlin files, open `example/android` in Android studio and find the source files at `reactnativetranscription` under `Android`. 55 | 56 | ### Commit message convention 57 | 58 | We follow the [conventional commits specification](https://www.conventionalcommits.org/en) for our commit messages: 59 | 60 | - `fix`: bug fixes, e.g. fix crash due to deprecated method. 61 | - `feat`: new features, e.g. add new method to the module. 62 | - `refactor`: code refactor, e.g. migrate from class components to hooks. 63 | - `docs`: changes into documentation, e.g. add usage example for the module.. 64 | - `test`: adding or updating tests, eg add integration tests using detox. 65 | - `chore`: tooling changes, e.g. change CI config. 66 | 67 | Our pre-commit hooks verify that your commit message matches this format when committing. 68 | 69 | ### Linting and tests 70 | 71 | [ESLint](https://eslint.org/), [Prettier](https://prettier.io/), [TypeScript](https://www.typescriptlang.org/) 72 | 73 | We use [TypeScript](https://www.typescriptlang.org/) for type checking, [ESLint](https://eslint.org/) with [Prettier](https://prettier.io/) for linting and formatting the code, and [Jest](https://jestjs.io/) for testing. 74 | 75 | Our pre-commit hooks verify that the linter and tests pass when committing. 76 | 77 | ### Scripts 78 | 79 | The `package.json` file contains various scripts for common tasks: 80 | 81 | - `yarn bootstrap`: setup project by installing all dependencies and pods. 82 | - `yarn typescript`: type-check files with TypeScript. 83 | - `yarn lint`: lint files with ESLint. 84 | - `yarn test`: run unit tests with Jest. 85 | - `yarn example start`: start the Metro server for the example app. 86 | - `yarn example android`: run the example app on Android. 87 | - `yarn example ios`: run the example app on iOS. 88 | 89 | ### Sending a pull request 90 | 91 | > **Working on your first pull request?** You can learn how from this _free_ series: [How to Contribute to an Open Source Project on GitHub](https://egghead.io/series/how-to-contribute-to-an-open-source-project-on-github). 92 | 93 | When you're sending a pull request: 94 | 95 | - Prefer small pull requests focused on one change. 96 | - Verify that linters and tests are passing. 97 | - Review the documentation to make sure it looks good. 98 | - Follow the pull request template when opening a pull request. 99 | - For pull requests that change the API or implementation, discuss with maintainers first by opening an issue. 100 | 101 | ## Code of Conduct 102 | 103 | ### Our Pledge 104 | 105 | We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation. 106 | 107 | We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community. 108 | 109 | ### Our Standards 110 | 111 | Examples of behavior that contributes to a positive environment for our community include: 112 | 113 | - Demonstrating empathy and kindness toward other people 114 | - Being respectful of differing opinions, viewpoints, and experiences 115 | - Giving and gracefully accepting constructive feedback 116 | - Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience 117 | - Focusing on what is best not just for us as individuals, but for the overall community 118 | 119 | Examples of unacceptable behavior include: 120 | 121 | - The use of sexualized language or imagery, and sexual attention or 122 | advances of any kind 123 | - Trolling, insulting or derogatory comments, and personal or political attacks 124 | - Public or private harassment 125 | - Publishing others' private information, such as a physical or email 126 | address, without their explicit permission 127 | - Other conduct which could reasonably be considered inappropriate in a 128 | professional setting 129 | 130 | ### Enforcement Responsibilities 131 | 132 | Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful. 133 | 134 | Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate. 135 | 136 | ### Scope 137 | 138 | This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. 139 | 140 | ### Enforcement 141 | 142 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at [INSERT CONTACT METHOD]. All complaints will be reviewed and investigated promptly and fairly. 143 | 144 | All community leaders are obligated to respect the privacy and security of the reporter of any incident. 145 | 146 | ### Enforcement Guidelines 147 | 148 | Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct: 149 | 150 | #### 1. Correction 151 | 152 | **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community. 153 | 154 | **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested. 155 | 156 | #### 2. Warning 157 | 158 | **Community Impact**: A violation through a single incident or series of actions. 159 | 160 | **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban. 161 | 162 | #### 3. Temporary Ban 163 | 164 | **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior. 165 | 166 | **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban. 167 | 168 | #### 4. Permanent Ban 169 | 170 | **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals. 171 | 172 | **Consequence**: A permanent ban from any sort of public interaction within the community. 173 | 174 | ### Attribution 175 | 176 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0, 177 | available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. 178 | 179 | Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity). 180 | 181 | [homepage]: https://www.contributor-covenant.org 182 | 183 | For answers to common questions about this code of conduct, see the FAQ at 184 | https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations. 185 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Ryan Tremblay 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # react-native-transcription 2 | 3 | Transcribe live and recorded audio on Android and iOS (live audio not currently available for iOS) 4 | 5 | ## Installation 6 | 7 | ```sh 8 | npm install react-native-transcription 9 | ``` 10 | ### iOS 11 | 12 | Mozilla DeepSpeech is only available as a Dynamic Framework, so we have to use a cocoapods plugin to avoid using `use_frameworks!` which breaks many other libraries. 13 | 14 | Run: 15 | ``` Bash 16 | $ sudo gem install cocoapods-user-defined-build-types 17 | ``` 18 | 19 | at the top of your podfile, add 20 | 21 | ```ruby 22 | plugin 'cocoapods-user-defined-build-types' 23 | enable_user_defined_build_types! 24 | ``` 25 | 26 | then add the build_type tag to the react-native-transcription pod in your podfile. 27 | ```ruby 28 | pod 'react-native-transcription', :build_type => :dynamic_framework, :path => 'THIS/IS/DIFFERENT/FOR/YOU' 29 | ``` 30 | 31 | then run `pod install`. 32 | 33 | Then open your project in Xcode and add the libdeepspeech.so (you can find it either in the DeepSpeech repo releases or in node_modules/react-native-transcription/ios/Frameworks) file to your Target's "Frameworks, Libraries, and Embedded Content" section: 34 | ![Screen Shot 2020-08-26 at 8 17 36 PM](https://user-images.githubusercontent.com/1612230/91369225-459c1d80-e7d9-11ea-86e2-f535fe65cd2e.png) 35 | 36 | 37 | ## Example App 38 | 39 | To get started with the example project, run `yarn bootstrap` in the root directory to install the required dependencies for each package: 40 | 41 | ```sh 42 | yarn bootstrap 43 | ``` 44 | 45 | Run the [example app](/example/) on your preferred platform. 46 | 47 | To run the example app on Android: 48 | 49 | ```sh 50 | yarn example android 51 | ``` 52 | 53 | To run the example app on iOS: 54 | 55 | ```sh 56 | yarn example ios 57 | ``` 58 | 59 | ## Usage 60 | 61 | It's easiest to read the [example's code.](https://github.com/zaptrem/react-native-transcription/blob/master/example/src/App.js) 62 | 63 | 1. Download models from the Mozilla-STT repo to the local file system and save the URIs. We used RNBackgroundDownloader as the files are too large to assume a continuous session for the whole download. 64 | 65 | 66 | ```js 67 | import Transcription from "react-native-transcription"; 68 | import { NativeEventEmitter } from 'react-native'; 69 | 70 | // Transcribe a .wav file 71 | Transcription.transcribeWav(wavFileURI, modelURI, scorerURI) 72 | 73 | // Start a streaming/live transcription. 74 | Transcription.startRecording(aacFileURI, modelURI, scorerURI) 75 | 76 | // Stop the transcription 77 | Transcription.stopRecording 78 | 79 | // Listen to changes in the live transcription 80 | this.callThisToUnsubscribe1 = TranscriptEvents.addListener("onRecordingChange", res => { 81 | console.log("onRecordingChange event", res); 82 | var transcriptionString = ""; 83 | for(word in res.words){ 84 | transcriptionString = (transcriptionString + res.words[word] + " "); 85 | } 86 | this.setState({ result: transcriptionString }); 87 | }); 88 | 89 | // Listen for final transcription 90 | this.callThisToUnsubscribe2 = TranscriptEvents.addListener("onRecordingCompletion", res => { 91 | console.log("onRecordingcompletion event", res); 92 | var transcriptionString = ""; 93 | for(word in res.words){ 94 | transcriptionString = (transcriptionString + res.words[word] + " "); 95 | } 96 | this.setState({ result: transcriptionString }); 97 | }); 98 | 99 | 100 | ``` 101 | 102 | ## Contributing 103 | 104 | See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow. 105 | 106 | ## License 107 | 108 | MIT 109 | -------------------------------------------------------------------------------- /Transcription.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Transcription.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /android/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | android_ 4 | Project android_ created by Buildship. 5 | 6 | 7 | 8 | 9 | org.eclipse.buildship.core.gradleprojectbuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.buildship.core.gradleprojectnature 16 | 17 | 18 | -------------------------------------------------------------------------------- /android/.settings/org.eclipse.buildship.core.prefs: -------------------------------------------------------------------------------- 1 | arguments= 2 | auto.sync=false 3 | build.scans.enabled=false 4 | connection.gradle.distribution=GRADLE_DISTRIBUTION(VERSION(6.0)) 5 | connection.project.dir= 6 | eclipse.preferences.version=1 7 | gradle.user.home= 8 | java.home=/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home 9 | jvm.arguments= 10 | offline.mode=false 11 | override.workspace.settings=true 12 | show.console.view=true 13 | show.executions.view=true 14 | -------------------------------------------------------------------------------- /android/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | // Buildscript is evaluated before everything else so we can't use getExtOrDefault 3 | def kotlin_version = rootProject.ext.has('kotlinVersion') ? rootProject.ext.get('kotlinVersion') : project.properties['Transcription_kotlinVersion'] 4 | 5 | repositories { 6 | google() 7 | jcenter() 8 | } 9 | 10 | dependencies { 11 | classpath 'com.android.tools.build:gradle:4.0.1' 12 | // noinspection DifferentKotlinGradleVersion 13 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 14 | } 15 | } 16 | 17 | apply plugin: 'com.android.library' 18 | apply plugin: 'kotlin-android' 19 | 20 | def getExtOrDefault(name) { 21 | return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['Transcription_' + name] 22 | } 23 | 24 | def getExtOrIntegerDefault(name) { 25 | return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties['Transcription_' + name]).toInteger() 26 | } 27 | 28 | android { 29 | compileSdkVersion getExtOrIntegerDefault('compileSdkVersion') 30 | buildToolsVersion getExtOrDefault('buildToolsVersion') 31 | defaultConfig { 32 | minSdkVersion 22 33 | targetSdkVersion getExtOrIntegerDefault('targetSdkVersion') 34 | versionCode 1 35 | versionName "1.0" 36 | 37 | } 38 | 39 | buildTypes { 40 | release { 41 | minifyEnabled false 42 | } 43 | } 44 | lintOptions { 45 | disable 'GradleCompatible' 46 | } 47 | compileOptions { 48 | sourceCompatibility JavaVersion.VERSION_1_8 49 | targetCompatibility JavaVersion.VERSION_1_8 50 | } 51 | } 52 | 53 | repositories { 54 | mavenCentral() 55 | jcenter() 56 | google() 57 | 58 | def found = false 59 | def defaultDir = null 60 | def androidSourcesName = 'React Native sources' 61 | 62 | if (rootProject.ext.has('reactNativeAndroidRoot')) { 63 | defaultDir = rootProject.ext.get('reactNativeAndroidRoot') 64 | } else { 65 | defaultDir = new File( 66 | projectDir, 67 | '/../../../node_modules/react-native/android' 68 | ) 69 | } 70 | 71 | if (defaultDir.exists()) { 72 | maven { 73 | url defaultDir.toString() 74 | name androidSourcesName 75 | } 76 | 77 | logger.info(":${project.name}:reactNativeAndroidRoot ${defaultDir.canonicalPath}") 78 | found = true 79 | } else { 80 | def parentDir = rootProject.projectDir 81 | 82 | 1.upto(5, { 83 | if (found) return true 84 | parentDir = parentDir.parentFile 85 | 86 | def androidSourcesDir = new File( 87 | parentDir, 88 | 'node_modules/react-native' 89 | ) 90 | 91 | def androidPrebuiltBinaryDir = new File( 92 | parentDir, 93 | 'node_modules/react-native/android' 94 | ) 95 | 96 | if (androidPrebuiltBinaryDir.exists()) { 97 | maven { 98 | url androidPrebuiltBinaryDir.toString() 99 | name androidSourcesName 100 | } 101 | 102 | logger.info(":${project.name}:reactNativeAndroidRoot ${androidPrebuiltBinaryDir.canonicalPath}") 103 | found = true 104 | } else if (androidSourcesDir.exists()) { 105 | maven { 106 | url androidSourcesDir.toString() 107 | name androidSourcesName 108 | } 109 | 110 | logger.info(":${project.name}:reactNativeAndroidRoot ${androidSourcesDir.canonicalPath}") 111 | found = true 112 | } 113 | }) 114 | } 115 | 116 | if (!found) { 117 | throw new GradleException( 118 | "${project.name}: unable to locate React Native android sources. " + 119 | "Ensure you have you installed React Native as a dependency in your project and try again." 120 | ) 121 | } 122 | } 123 | 124 | def kotlin_version = getExtOrDefault('kotlinVersion') 125 | 126 | dependencies { 127 | 128 | implementation fileTree(dir: 'lib-main', include: ['*.so']) 129 | implementation fileTree(dir: 'libs', include: ['*.jar']) 130 | // noinspection GradleDynamicVersion 131 | api 'com.facebook.react:react-native:+' 132 | 133 | implementation 'androidx.appcompat:appcompat:1.0.2' 134 | implementation 'androidx.core:core-ktx:1.0.2' 135 | implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" 136 | implementation 'org.mozilla.deepspeech:libdeepspeech:0.9.2' 137 | } 138 | -------------------------------------------------------------------------------- /android/gradle.properties: -------------------------------------------------------------------------------- 1 | Transcription_kotlinVersion=1.3.50 2 | Transcription_compileSdkVersion=29 3 | Transcription_buildToolsVersion=28.0.3 4 | Transcription_targetSdkVersion=29 5 | android.useAndroidX=true 6 | android.enableJetifier=true 7 | -------------------------------------------------------------------------------- /android/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReLearnApp/react-native-transcription/8809e9ae01eca460ebf3e0184d77af961b3e39e2/android/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /android/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Aug 18 23:02:19 EDT 2020 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip 7 | -------------------------------------------------------------------------------- /android/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /android/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /android/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /android/src/main/java/com/reactnativetranscription/AdtsHeaderBuilder.java: -------------------------------------------------------------------------------- 1 | package com.reactnativetranscription; 2 | 3 | import android.media.MediaCodecInfo; 4 | 5 | public class AdtsHeaderBuilder { 6 | public static byte[] createAdtsHeader(int length, int SAMPLE_RATE_INDEX, int CHANNELS) { 7 | int frameLength = length + 7; 8 | byte[] adtsHeader = new byte[7]; 9 | 10 | adtsHeader[0] = (byte) 0xFF; // Sync Word 11 | adtsHeader[1] = (byte) 0xF1; // MPEG-4, Layer (0), No CRC 12 | adtsHeader[2] = (byte) ((MediaCodecInfo.CodecProfileLevel.AACObjectLC - 1) << 6); 13 | adtsHeader[2] |= (((byte) SAMPLE_RATE_INDEX) << 2); 14 | adtsHeader[2] |= (((byte) CHANNELS) >> 2); 15 | adtsHeader[3] = (byte) (((CHANNELS & 3) << 6) | ((frameLength >> 11) & 0x03)); 16 | adtsHeader[4] = (byte) ((frameLength >> 3) & 0xFF); 17 | adtsHeader[5] = (byte) (((frameLength & 0x07) << 5) | 0x1f); 18 | adtsHeader[6] = (byte) 0xFC; 19 | 20 | return adtsHeader; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /android/src/main/java/com/reactnativetranscription/AudioRecordThread.kt: -------------------------------------------------------------------------------- 1 | package com.reactnativetranscription 2 | 3 | import com.facebook.react.bridge.ReactApplicationContext 4 | import com.facebook.react.bridge.ReactContextBaseJavaModule 5 | import com.facebook.react.bridge.ReactMethod 6 | import com.facebook.react.bridge.Promise 7 | import com.facebook.react.bridge.WritableMap 8 | import com.facebook.react.bridge.Arguments; 9 | import com.facebook.react.modules.core.DeviceEventManagerModule 10 | 11 | 12 | import android.media.* 13 | import android.media.MediaCodec.BufferInfo 14 | import android.media.audiofx.AutomaticGainControl 15 | import android.media.audiofx.NoiseSuppressor 16 | import android.os.Build 17 | import android.util.Log 18 | import java.io.IOException 19 | import java.io.OutputStream 20 | import java.nio.ByteBuffer 21 | import kotlin.experimental.or 22 | import java.io.File 23 | 24 | import org.mozilla.deepspeech.libdeepspeech.DeepSpeechModel 25 | import com.reactnativetranscription.AdtsHeaderBuilder.createAdtsHeader 26 | import org.mozilla.deepspeech.libdeepspeech.DeepSpeechStreamingState 27 | 28 | //import kotlin.Throws 29 | 30 | class AudioRecordThread internal constructor(outputStream: OutputStream, onRecorderFailedListener: OnRecorderFailedListener?, modelPath: String, scorerPath: String, reactContext: ReactApplicationContext) : Runnable { 31 | 32 | private var reactContext = reactContext 33 | private var model: DeepSpeechModel? = null 34 | private var streamContext: DeepSpeechStreamingState? = null 35 | private var modelPath: String = modelPath 36 | private var scorerPath: String = scorerPath 37 | 38 | private var transcriptionThread: Thread? = null 39 | 40 | private var lastTranscription: String = "" 41 | 42 | private val bufferSize: Int 43 | private val mediaCodec: MediaCodec 44 | private val audioRecord: AudioRecord 45 | private val outputStream: OutputStream 46 | private val onRecorderFailedListener: OnRecorderFailedListener? 47 | 48 | fun createModel(): Boolean { 49 | for (path in listOf(modelPath, scorerPath)) { 50 | if (!File(path).exists()) { 51 | throw Exception("Model creation failed: $path does not exist.\n") 52 | return false 53 | } 54 | } 55 | 56 | model = DeepSpeechModel(modelPath) 57 | model?.enableExternalScorer(scorerPath) 58 | 59 | return true 60 | } 61 | 62 | override fun run() { 63 | if (onRecorderFailedListener != null) { 64 | Log.d(TAG, "onRecorderStarted") 65 | onRecorderFailedListener.onRecorderStarted() 66 | } 67 | if (model == null) { 68 | if (!createModel()) { 69 | return 70 | } 71 | Log.d("transcription","Created model.\n") 72 | } 73 | model?.let{ model -> streamContext = model.createStream() } 74 | val bufferInfo = BufferInfo() 75 | val codecInputBuffers = mediaCodec.inputBuffers 76 | val codecOutputBuffers = mediaCodec.outputBuffers 77 | try { 78 | while (!Thread.interrupted()) { 79 | val success = handleCodecInput(audioRecord, mediaCodec, codecInputBuffers, Thread.currentThread().isAlive) 80 | if (success) handleCodecOutput(mediaCodec, codecOutputBuffers, bufferInfo, outputStream) 81 | } 82 | } catch (e: IOException) { 83 | Log.w(TAG, e) 84 | } finally { 85 | model?.let{ model -> 86 | val decoded = model.finishStreamWithMetadata(streamContext, 1) 87 | val map = packageTranscription(decoded) 88 | emitDeviceEvent("onRecordingCompletion", map) 89 | if (model != null) { 90 | model?.freeModel() 91 | } 92 | } 93 | 94 | mediaCodec.stop() 95 | audioRecord.stop() 96 | mediaCodec.release() 97 | audioRecord.release() 98 | try { 99 | outputStream.close() 100 | } catch (e: IOException) { 101 | e.printStackTrace() 102 | } 103 | } 104 | } 105 | 106 | @Throws(IOException::class) 107 | private fun handleCodecInput(audioRecord: AudioRecord, 108 | mediaCodec: MediaCodec, codecInputBuffers: Array, 109 | running: Boolean): Boolean { 110 | val audioRecordData = ByteArray(bufferSize) 111 | val length = audioRecord.read(audioRecordData, 0, audioRecordData.size) 112 | 113 | model?.let { model -> 114 | streamContext?.let { streamContext -> 115 | val shortArray = ShortArray(audioRecordData.size / 2) { 116 | (audioRecordData[it * 2].toUByte().toInt() + (audioRecordData[(it * 2) + 1].toInt() shl 8)).toShort() 117 | } 118 | model.feedAudioContent(streamContext, shortArray, shortArray.size) 119 | val decoded = model.intermediateDecodeWithMetadata(streamContext, 1) 120 | val decodedString = model.intermediateDecode(streamContext) 121 | 122 | if(decodedString != lastTranscription){ 123 | lastTranscription = decodedString 124 | val map = packageTranscription(decoded) 125 | emitDeviceEvent("onRecordingChange", map) 126 | Log.d("transcription", decodedString) 127 | } 128 | } 129 | } 130 | if (length == AudioRecord.ERROR_BAD_VALUE || length == AudioRecord.ERROR_INVALID_OPERATION || length != bufferSize) { 131 | if (length != bufferSize) { 132 | if (onRecorderFailedListener != null) { 133 | Log.d(TAG, "length != BufferSize calling onRecordFailed") 134 | onRecorderFailedListener.onRecorderFailed() 135 | } 136 | return false 137 | } 138 | } 139 | val codecInputBufferIndex = mediaCodec.dequeueInputBuffer(10 * 1000.toLong()) 140 | if (codecInputBufferIndex >= 0) { 141 | val codecBuffer = codecInputBuffers[codecInputBufferIndex] 142 | codecBuffer.clear() 143 | codecBuffer.put(audioRecordData) 144 | mediaCodec.queueInputBuffer(codecInputBufferIndex, 0, length, 0, if (running) 0 else MediaCodec.BUFFER_FLAG_END_OF_STREAM) 145 | } 146 | return true 147 | } 148 | 149 | @Throws(IOException::class) 150 | private fun handleCodecOutput(mediaCodec: MediaCodec, 151 | codecOutputBuffers: Array, 152 | bufferInfo: BufferInfo, 153 | outputStream: OutputStream) { 154 | var codecOutputBuffers = codecOutputBuffers 155 | var codecOutputBufferIndex = mediaCodec.dequeueOutputBuffer(bufferInfo, 0) 156 | while (codecOutputBufferIndex != MediaCodec.INFO_TRY_AGAIN_LATER) { 157 | if (codecOutputBufferIndex >= 0) { 158 | val encoderOutputBuffer = codecOutputBuffers[codecOutputBufferIndex] 159 | encoderOutputBuffer.position(bufferInfo.offset) 160 | encoderOutputBuffer.limit(bufferInfo.offset + bufferInfo.size) 161 | if (bufferInfo.flags and MediaCodec.BUFFER_FLAG_CODEC_CONFIG != MediaCodec.BUFFER_FLAG_CODEC_CONFIG) { 162 | val header = createAdtsHeader(bufferInfo.size - bufferInfo.offset, SAMPLE_RATE_INDEX, CHANNELS) 163 | outputStream.write(header) 164 | val data = ByteArray(encoderOutputBuffer.remaining()) 165 | encoderOutputBuffer[data] 166 | outputStream.write(data) 167 | } 168 | encoderOutputBuffer.clear() 169 | mediaCodec.releaseOutputBuffer(codecOutputBufferIndex, false) 170 | } else if (codecOutputBufferIndex == MediaCodec.INFO_OUTPUT_BUFFERS_CHANGED) { 171 | codecOutputBuffers = mediaCodec.outputBuffers 172 | } 173 | codecOutputBufferIndex = mediaCodec.dequeueOutputBuffer(bufferInfo, 0) 174 | } 175 | } 176 | private fun emitDeviceEvent(eventName: String, eventData: WritableMap?) { 177 | // A method for emitting from the native side to JS 178 | // https://facebook.github.io/react-native/docs/native-modules-android.html#sending-events-to-javascript 179 | reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java).emit(eventName, eventData) 180 | } 181 | private fun packageTranscription(decoded: org.mozilla.deepspeech.libdeepspeech.Metadata): com.facebook.react.bridge.WritableMap { 182 | var map = Arguments.createMap() 183 | val transcriptCandidate = decoded.getTranscript(0) 184 | val words = Arguments.createArray() 185 | val timestamps = Arguments.createArray() 186 | 187 | var workingString = StringBuilder() 188 | var lastTimestamp = -1 189 | for (x in 0..(transcriptCandidate.getNumTokens() - 1)){ 190 | val token = transcriptCandidate.getToken(x.toInt()) 191 | val text = token.getText() 192 | val timestamp = token.getStartTime() 193 | if(lastTimestamp == -1){ 194 | lastTimestamp = timestamp.toInt() 195 | } 196 | if(text == " " || x == (transcriptCandidate.getNumTokens() - 1)){ 197 | // Append timestamp, reset string, reset timestamp to -1 198 | words.pushString(workingString.toString()) 199 | timestamps.pushInt(lastTimestamp) 200 | workingString = StringBuilder() 201 | lastTimestamp = -1 202 | }else{ 203 | workingString.append(text) 204 | } 205 | } 206 | map.putArray("words", words) 207 | map.putArray("timestamps", timestamps) 208 | return map; 209 | } 210 | 211 | 212 | private fun createAudioRecord(bufferSize: Int): AudioRecord { 213 | val audioRecord = AudioRecord(MediaRecorder.AudioSource.MIC, SAMPLE_RATE, 214 | AudioFormat.CHANNEL_IN_MONO, 215 | AudioFormat.ENCODING_PCM_16BIT, bufferSize * 10) 216 | if (audioRecord.state != AudioRecord.STATE_INITIALIZED) { 217 | Log.d(TAG, "Unable to initialize AudioRecord") 218 | throw RuntimeException("Unable to initialize AudioRecord") 219 | } 220 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { 221 | if (NoiseSuppressor.isAvailable()) { 222 | val noiseSuppressor = NoiseSuppressor 223 | .create(audioRecord.audioSessionId) 224 | if (noiseSuppressor != null) { 225 | noiseSuppressor.enabled = true 226 | } 227 | } 228 | } 229 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { 230 | if (AutomaticGainControl.isAvailable()) { 231 | val automaticGainControl = AutomaticGainControl 232 | .create(audioRecord.audioSessionId) 233 | if (automaticGainControl != null) { 234 | automaticGainControl.enabled = true 235 | } 236 | } 237 | } 238 | return audioRecord 239 | } 240 | 241 | @Throws(IOException::class) 242 | private fun createMediaCodec(bufferSize: Int): MediaCodec { 243 | val mediaCodec = MediaCodec.createEncoderByType("audio/mp4a-latm") 244 | val mediaFormat = MediaFormat() 245 | mediaFormat.setString(MediaFormat.KEY_MIME, "audio/mp4a-latm") 246 | mediaFormat.setInteger(MediaFormat.KEY_SAMPLE_RATE, SAMPLE_RATE) 247 | mediaFormat.setInteger(MediaFormat.KEY_CHANNEL_COUNT, CHANNELS) 248 | mediaFormat.setInteger(MediaFormat.KEY_MAX_INPUT_SIZE, bufferSize) 249 | mediaFormat.setInteger(MediaFormat.KEY_BIT_RATE, BIT_RATE) 250 | mediaFormat.setInteger(MediaFormat.KEY_AAC_PROFILE, MediaCodecInfo.CodecProfileLevel.AACObjectLC) 251 | try { 252 | mediaCodec.configure(mediaFormat, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE) 253 | } catch (e: Exception) { 254 | Log.w(TAG, e) 255 | mediaCodec.release() 256 | throw IOException(e) 257 | } 258 | return mediaCodec 259 | } 260 | 261 | internal interface OnRecorderFailedListener { 262 | fun onRecorderFailed() 263 | fun onRecorderStarted() 264 | } 265 | 266 | companion object { 267 | private val TAG = AudioRecordThread::class.java.simpleName 268 | //private const val SAMPLE_RATE = 44100 269 | private const val SAMPLE_RATE = 16000 270 | //private const val SAMPLE_RATE_INDEX = 4 271 | private const val SAMPLE_RATE_INDEX = 8 272 | private const val CHANNELS = 1 273 | private const val BIT_RATE = 32000 274 | } 275 | 276 | init { 277 | bufferSize = AudioRecord.getMinBufferSize(SAMPLE_RATE, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT) 278 | audioRecord = createAudioRecord(bufferSize) 279 | mediaCodec = createMediaCodec(bufferSize) 280 | this.outputStream = outputStream 281 | this.onRecorderFailedListener = onRecorderFailedListener 282 | mediaCodec.start() 283 | try { 284 | audioRecord.startRecording() 285 | } catch (e: Exception) { 286 | Log.w(TAG, e) 287 | mediaCodec.release() 288 | throw IOException(e) 289 | } 290 | } 291 | } 292 | -------------------------------------------------------------------------------- /android/src/main/java/com/reactnativetranscription/FileTranscriptionModule.kt: -------------------------------------------------------------------------------- 1 | package com.reactnativetranscription 2 | 3 | import android.util.Log 4 | import com.facebook.react.bridge.Arguments 5 | import com.facebook.react.bridge.ReactApplicationContext 6 | import com.facebook.react.bridge.ReactContextBaseJavaModule 7 | import com.facebook.react.bridge.WritableMap 8 | import com.facebook.react.bridge.ReactMethod 9 | import com.facebook.react.modules.core.DeviceEventManagerModule 10 | import org.mozilla.deepspeech.libdeepspeech.DeepSpeechModel 11 | import java.io.File 12 | import java.io.FileNotFoundException 13 | import java.io.IOException 14 | import java.io.RandomAccessFile 15 | import java.nio.ByteBuffer 16 | import java.nio.ByteOrder 17 | import com.reactnativetranscription.WavHeaderFunctions.* 18 | 19 | 20 | class FileTranscriptionModule(reactContext: ReactApplicationContext) { 21 | 22 | private val reactContext: ReactApplicationContext = reactContext 23 | 24 | var model: DeepSpeechModel? = null 25 | val BEAM_WIDTH = 50 26 | 27 | fun transcribeWav(audioFile: String, modelPath: String, scorerPath: String) { 28 | //var inferenceExecTime: Long = 0 29 | 30 | if (model == null) { 31 | for (path in listOf(modelPath, scorerPath)) { 32 | if (!File(path).exists()) { 33 | throw Exception("Model creation failed: $path does not exist.\n") 34 | } 35 | } 36 | 37 | 38 | model = DeepSpeechModel(modelPath) 39 | model?.enableExternalScorer(scorerPath) 40 | model!!.setBeamWidth(BEAM_WIDTH.toLong()) 41 | //model!!.setScorerAlphaBeta(0.931289039105002F, 1.1834137581510284F) 42 | Log.d("transcription","Created model.\n") 43 | } 44 | 45 | //this._startInference.setEnabled(false) 46 | //newModel(this._tfliteModel.getText().toString()) 47 | //this._tfliteStatus.setText("Extracting audio features ...") 48 | if (!File(audioFile).exists()) { 49 | throw Exception("File transcription failed: $audioFile does not exist.\n") 50 | } 51 | Log.d("transcription","Extracting audio features\n") 52 | try { 53 | val wave = RandomAccessFile(audioFile, "r") 54 | wave.seek(20) 55 | val audioFormat: Char = readLEChar(wave) 56 | if(audioFormat.toInt() != 1 // 1 is PCM 57 | ) throw Exception("File isn't PCM") 58 | wave.seek(22) 59 | val numChannels: Char = readLEChar(wave) 60 | if(numChannels.toInt() != 1 // MONO 61 | ) throw Exception("File isn't mono") 62 | wave.seek(24) 63 | val sampleRate: Int = readLEInt(wave) 64 | if(sampleRate != model!!.sampleRate() // desired sample rate 65 | ) throw Exception("File isn't 16000hz") 66 | wave.seek(34) 67 | val bitsPerSample: Char = readLEChar(wave) 68 | if(bitsPerSample.toInt() != 16 // 16 bits per sample 69 | ) throw Exception("File isn't 16 bit") 70 | // tv_bitsPerSample.setText("bitsPerSample=" + (bitsPerSample == 16 ? "16-bits" : "!16-bits" )); 71 | wave.seek(40) 72 | val bufferSize: Int = readLEInt(wave) 73 | if(bufferSize <= 0) throw Exception("Buffer size is wrong") 74 | wave.seek(44) 75 | val bytes = ByteArray(bufferSize) 76 | wave.readFully(bytes) 77 | val shorts = ShortArray(bytes.size / 2) 78 | // to turn bytes to shorts as either big endian or little endian. 79 | ByteBuffer.wrap(bytes).order(ByteOrder.LITTLE_ENDIAN).asShortBuffer()[shorts] 80 | //this._tfliteStatus.setText("Running inference ...") 81 | Log.d("transcription","Running inference\n") 82 | //val inferenceStartTime = System.currentTimeMillis() 83 | 84 | // sphinx-doc: java_ref_inference_start 85 | val decoded = model!!.sttWithMetadata(shorts, shorts.size, 1) 86 | Log.d("transcription","Inference complete\n") 87 | // sphinx-doc: java_ref_inference_stop 88 | //inferenceExecTime = System.currentTimeMillis() - inferenceStartTime 89 | //this._decodedString.setText(decoded) 90 | val map = packageTranscription(decoded) 91 | emitDeviceEvent("onWavTranscribed", map) 92 | if (model != null) { 93 | model?.freeModel() 94 | } 95 | 96 | } catch (ex: FileNotFoundException) { 97 | } catch (ex: IOException) { 98 | } finally { 99 | } 100 | } 101 | 102 | private fun emitDeviceEvent(eventName: String, eventData: WritableMap?) { 103 | // A method for emitting from the native side to JS 104 | // https://facebook.github.io/react-native/docs/native-modules-android.html#sending-events-to-javascript 105 | reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java).emit(eventName, eventData) 106 | } 107 | 108 | private fun packageTranscription(decoded: org.mozilla.deepspeech.libdeepspeech.Metadata): com.facebook.react.bridge.WritableMap { 109 | var map = Arguments.createMap() 110 | val transcriptCandidate = decoded.getTranscript(0) 111 | val words = Arguments.createArray() 112 | val timestamps = Arguments.createArray() 113 | 114 | var workingString = StringBuilder() 115 | var lastTimestamp = -1 116 | for (x in 0..(transcriptCandidate.getNumTokens() - 1)){ 117 | val token = transcriptCandidate.getToken(x.toInt()) 118 | val text = token.getText() 119 | val timestamp = token.getStartTime() 120 | if(lastTimestamp == -1){ 121 | lastTimestamp = timestamp.toInt() 122 | } 123 | if(text == " " || x == (transcriptCandidate.getNumTokens() - 1)){ 124 | // Append timestamp, reset string, reset timestamp to -1 125 | words.pushString(workingString.toString()) 126 | timestamps.pushInt(lastTimestamp) 127 | workingString = StringBuilder() 128 | lastTimestamp = -1 129 | }else{ 130 | workingString.append(text) 131 | } 132 | } 133 | map.putArray("words", words) 134 | map.putArray("timestamps", timestamps) 135 | return map; 136 | } 137 | 138 | } 139 | -------------------------------------------------------------------------------- /android/src/main/java/com/reactnativetranscription/OnAudioRecordListener.kt: -------------------------------------------------------------------------------- 1 | package com.reactnativetranscription 2 | 3 | //import kotlin.Throws 4 | 5 | interface OnAudioRecordListener { 6 | fun onRecordFinished(recordingItem: RecordingItem?) 7 | fun onError(errorCode: Int) 8 | fun onRecordingStarted() 9 | } 10 | -------------------------------------------------------------------------------- /android/src/main/java/com/reactnativetranscription/RecordingItem.kt: -------------------------------------------------------------------------------- 1 | package com.reactnativetranscription 2 | 3 | import android.os.Parcel 4 | import android.os.Parcelable 5 | import android.os.Parcelable.Creator 6 | //import kotlin.Throws 7 | 8 | class RecordingItem : Parcelable { 9 | var name: String? = null 10 | var filePath: String? = null 11 | var id = 0 12 | var length = 0 13 | var time: Long = 0 14 | 15 | constructor() {} 16 | constructor(`in`: Parcel) { 17 | name = `in`.readString() 18 | filePath = `in`.readString() 19 | id = `in`.readInt() 20 | length = `in`.readInt() 21 | time = `in`.readLong() 22 | } 23 | 24 | override fun writeToParcel(dest: Parcel, flags: Int) { 25 | dest.writeInt(id) 26 | dest.writeInt(length) 27 | dest.writeLong(time) 28 | dest.writeString(filePath) 29 | dest.writeString(name) 30 | } 31 | 32 | override fun describeContents(): Int { 33 | return 0 34 | } 35 | 36 | companion object { 37 | val CREATOR: Creator = object : Creator { 38 | override fun createFromParcel(`in`: Parcel): RecordingItem? { 39 | return RecordingItem(`in`) 40 | } 41 | 42 | override fun newArray(size: Int): Array { 43 | return arrayOfNulls(size) 44 | } 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /android/src/main/java/com/reactnativetranscription/TranscriptionModule.kt: -------------------------------------------------------------------------------- 1 | package com.reactnativetranscription 2 | 3 | import com.facebook.react.bridge.ReactApplicationContext 4 | import com.facebook.react.bridge.ReactContextBaseJavaModule 5 | import com.facebook.react.bridge.ReactMethod 6 | import com.facebook.react.bridge.Promise 7 | import com.facebook.react.bridge.WritableMap 8 | import com.facebook.react.bridge.Arguments; 9 | import com.facebook.react.modules.core.DeviceEventManagerModule 10 | 11 | 12 | import android.util.Log 13 | import com.reactnativetranscription.AudioRecordThread.OnRecorderFailedListener 14 | import java.io.* 15 | //import kotlin.Throws 16 | 17 | class TranscriptionModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) { 18 | 19 | private var reactContext = reactContext 20 | private var file: File? = null 21 | private var onAudioRecordListener: OnAudioRecordListener? = null 22 | private var mStartingTimeMillis: Long = 0 23 | private var mRecordingThread: Thread? = null 24 | 25 | override fun getName(): String { 26 | return "Transcription" 27 | } 28 | 29 | @ReactMethod 30 | private fun transcribeWav(wavPath: String, modelPath: String, scorerPath: String) { 31 | val fileTranscriber = FileTranscriptionModule(reactContext) 32 | fileTranscriber.transcribeWav(wavPath, modelPath, scorerPath) 33 | } 34 | 35 | fun setOnAudioRecordListener(onAudioRecordListener: OnAudioRecordListener?) { 36 | this.onAudioRecordListener = onAudioRecordListener 37 | } 38 | 39 | /*fun setFile(filePath: String?) { 40 | file = File(filePath) 41 | }*/ 42 | 43 | // Call this method from Activity onStartButton Click to start recording 44 | @Synchronized 45 | @ReactMethod 46 | fun startRecording(filePath: String, modelPath: String, scorerPath: String) { 47 | file = File(filePath) 48 | if (file == null) { 49 | //onAudioRecordListener!!.onError(FILE_NULL) 50 | return 51 | } 52 | mStartingTimeMillis = System.currentTimeMillis() 53 | try { 54 | if (mRecordingThread != null) stopRecording(true) 55 | mRecordingThread = Thread(AudioRecordThread(outputStream(file), object : OnRecorderFailedListener { 56 | override fun onRecorderFailed() { 57 | //onAudioRecordListener!!.onError(RECORDER_ERROR) 58 | stopRecording(true) 59 | } 60 | 61 | override fun onRecorderStarted() { 62 | //onAudioRecordListener!!.onRecordingStarted() 63 | } 64 | }, modelPath, scorerPath, reactContext)) 65 | mRecordingThread!!.name = "AudioRecordingThread" 66 | mRecordingThread!!.start() 67 | } catch (e: IOException) { 68 | e.printStackTrace() 69 | } 70 | } 71 | 72 | // Call this method from Activity onStopButton Click to stop recording 73 | @Synchronized 74 | @ReactMethod 75 | fun stopRecording(delete: Boolean?) { 76 | Log.d(TAG, "Recording stopped ") 77 | if (mRecordingThread != null) { 78 | mRecordingThread!!.interrupt() 79 | mRecordingThread = null 80 | if (file!!.length() == 0L) { 81 | //onAudioRecordListener!!.onError(IO_ERROR) 82 | return 83 | } 84 | val mElapsedMillis = System.currentTimeMillis() - mStartingTimeMillis 85 | val recordingItem = RecordingItem() 86 | recordingItem.filePath = file!!.absolutePath 87 | recordingItem.name = file!!.name 88 | recordingItem.length = mElapsedMillis.toInt() 89 | recordingItem.time = System.currentTimeMillis() 90 | if (!delete!!) { 91 | //onAudioRecordListener!!.onRecordFinished(recordingItem) 92 | } else { 93 | deleteFile() 94 | } 95 | } 96 | } 97 | 98 | private fun deleteFile() { 99 | if (file != null && file!!.exists()) Log.d(TAG, String.format("deleting file success %b ", file!!.delete())) 100 | } 101 | 102 | private fun outputStream(file: File?): OutputStream { 103 | if (file == null) { 104 | throw RuntimeException("file is null !") 105 | } 106 | val outputStream: OutputStream 107 | outputStream = try { 108 | file.createNewFile() 109 | FileOutputStream(file) 110 | } catch (e: FileNotFoundException) { 111 | throw RuntimeException( 112 | "could not build OutputStream from" + " this file " + file.name, e) 113 | } 114 | return outputStream 115 | } 116 | 117 | companion object { 118 | private const val TAG = "AudioRecording" 119 | private const val IO_ERROR = 1 120 | private const val RECORDER_ERROR = 2 121 | const val FILE_NULL = 3 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /android/src/main/java/com/reactnativetranscription/TranscriptionPackage.kt: -------------------------------------------------------------------------------- 1 | package com.reactnativetranscription 2 | 3 | import java.util.Arrays 4 | import java.util.Collections 5 | 6 | import com.facebook.react.ReactPackage 7 | import com.facebook.react.bridge.NativeModule 8 | import com.facebook.react.bridge.ReactApplicationContext 9 | import com.facebook.react.uimanager.ViewManager 10 | import com.facebook.react.bridge.JavaScriptModule 11 | 12 | class TranscriptionPackage : ReactPackage { 13 | override fun createNativeModules(reactContext: ReactApplicationContext): List { 14 | return Arrays.asList(TranscriptionModule(reactContext)) 15 | } 16 | 17 | override fun createViewManagers(reactContext: ReactApplicationContext): List> { 18 | return emptyList>() 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /android/src/main/java/com/reactnativetranscription/WavHeaderFunctions.java: -------------------------------------------------------------------------------- 1 | package com.reactnativetranscription; 2 | 3 | import java.io.RandomAccessFile; 4 | import java.io.FileNotFoundException; 5 | import java.io.IOException; 6 | import java.nio.ByteOrder; 7 | import java.nio.ByteBuffer; 8 | 9 | public class WavHeaderFunctions { 10 | public static char readLEChar(RandomAccessFile f) throws IOException { 11 | byte b1 = f.readByte(); 12 | byte b2 = f.readByte(); 13 | return (char)((b2 << 8) | b1); 14 | } 15 | 16 | public static int readLEInt(RandomAccessFile f) throws IOException { 17 | byte b1 = f.readByte(); 18 | byte b2 = f.readByte(); 19 | byte b3 = f.readByte(); 20 | byte b4 = f.readByte(); 21 | return (int)((b1 & 0xFF) | (b2 & 0xFF) << 8 | (b3 & 0xFF) << 16 | (b4 & 0xFF) << 24); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: ['module:metro-react-native-babel-preset'], 3 | }; 4 | -------------------------------------------------------------------------------- /example/android/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | android 4 | Project android created by Buildship. 5 | 6 | 7 | 8 | 9 | org.eclipse.buildship.core.gradleprojectbuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.buildship.core.gradleprojectnature 16 | 17 | 18 | -------------------------------------------------------------------------------- /example/android/.settings/org.eclipse.buildship.core.prefs: -------------------------------------------------------------------------------- 1 | connection.project.dir= 2 | eclipse.preferences.version=1 3 | -------------------------------------------------------------------------------- /example/android/app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: "com.android.application" 2 | 3 | import com.android.build.OutputFile 4 | 5 | /** 6 | * The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets 7 | * and bundleReleaseJsAndAssets). 8 | * These basically call `react-native bundle` with the correct arguments during the Android build 9 | * cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the 10 | * bundle directly from the development server. Below you can see all the possible configurations 11 | * and their defaults. If you decide to add a configuration block, make sure to add it before the 12 | * `apply from: "../../node_modules/react-native/react.gradle"` line. 13 | * 14 | * project.ext.react = [ 15 | * // the name of the generated asset file containing your JS bundle 16 | * bundleAssetName: "index.android.bundle", 17 | * 18 | * // the entry file for bundle generation 19 | * entryFile: "index.android.js", 20 | * 21 | * // https://facebook.github.io/react-native/docs/performance#enable-the-ram-format 22 | * bundleCommand: "ram-bundle", 23 | * 24 | * // whether to bundle JS and assets in debug mode 25 | * bundleInDebug: false, 26 | * 27 | * // whether to bundle JS and assets in release mode 28 | * bundleInRelease: true, 29 | * 30 | * // whether to bundle JS and assets in another build variant (if configured). 31 | * // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants 32 | * // The configuration property can be in the following formats 33 | * // 'bundleIn${productFlavor}${buildType}' 34 | * // 'bundleIn${buildType}' 35 | * // bundleInFreeDebug: true, 36 | * // bundleInPaidRelease: true, 37 | * // bundleInBeta: true, 38 | * 39 | * // whether to disable dev mode in custom build variants (by default only disabled in release) 40 | * // for TranscriptionExample: to disable dev mode in the staging build type (if configured) 41 | * devDisabledInStaging: true, 42 | * // The configuration property can be in the following formats 43 | * // 'devDisabledIn${productFlavor}${buildType}' 44 | * // 'devDisabledIn${buildType}' 45 | * 46 | * // the root of your project, i.e. where "package.json" lives 47 | * root: "../../", 48 | * 49 | * // where to put the JS bundle asset in debug mode 50 | * jsBundleDirDebug: "$buildDir/intermediates/assets/debug", 51 | * 52 | * // where to put the JS bundle asset in release mode 53 | * jsBundleDirRelease: "$buildDir/intermediates/assets/release", 54 | * 55 | * // where to put drawable resources / React Native assets, e.g. the ones you use via 56 | * // require('./image.png')), in debug mode 57 | * resourcesDirDebug: "$buildDir/intermediates/res/merged/debug", 58 | * 59 | * // where to put drawable resources / React Native assets, e.g. the ones you use via 60 | * // require('./image.png')), in release mode 61 | * resourcesDirRelease: "$buildDir/intermediates/res/merged/release", 62 | * 63 | * // by default the gradle tasks are skipped if none of the JS files or assets change; this means 64 | * // that we don't look at files in android/ or ios/ to determine whether the tasks are up to 65 | * // date; if you have any other folders that you want to ignore for performance reasons (gradle 66 | * // indexes the entire tree), add them here. Alternatively, if you have JS files in android/ 67 | * // for TranscriptionExample, you might want to remove it from here. 68 | * inputExcludes: ["android/**", "ios/**"], 69 | * 70 | * // override which node gets called and with what additional arguments 71 | * nodeExecutableAndArgs: ["node"], 72 | * 73 | * // supply additional arguments to the packager 74 | * extraPackagerArgs: [] 75 | * ] 76 | */ 77 | 78 | project.ext.react = [ 79 | enableHermes: false, // clean and rebuild if changing 80 | ] 81 | 82 | apply from: "../../node_modules/react-native/react.gradle" 83 | 84 | /** 85 | * Set this to true to create two separate APKs instead of one: 86 | * - An APK that only works on ARM devices 87 | * - An APK that only works on x86 devices 88 | * The advantage is the size of the APK is reduced by about 4MB. 89 | * Upload all the APKs to the Play Store and people will download 90 | * the correct one based on the CPU architecture of their device. 91 | */ 92 | def enableSeparateBuildPerCPUArchitecture = false 93 | 94 | /** 95 | * Run Proguard to shrink the Java bytecode in release builds. 96 | */ 97 | def enableProguardInReleaseBuilds = false 98 | 99 | /** 100 | * The preferred build flavor of JavaScriptCore. 101 | * 102 | * For TranscriptionExample, to use the international variant, you can use: 103 | * `def jscFlavor = 'org.webkit:android-jsc-intl:+'` 104 | * 105 | * The international variant includes ICU i18n library and necessary data 106 | * allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that 107 | * give correct results when using with locales other than en-US. Note that 108 | * this variant is about 6MiB larger per architecture than default. 109 | */ 110 | def jscFlavor = 'org.webkit:android-jsc:+' 111 | 112 | /** 113 | * Whether to enable the Hermes VM. 114 | * 115 | * This should be set on project.ext.react and mirrored here. If it is not set 116 | * on project.ext.react, JavaScript will not be compiled to Hermes Bytecode 117 | * and the benefits of using Hermes will therefore be sharply reduced. 118 | */ 119 | def enableHermes = project.ext.react.get("enableHermes", false); 120 | 121 | android { 122 | compileSdkVersion rootProject.ext.compileSdkVersion 123 | 124 | compileOptions { 125 | sourceCompatibility JavaVersion.VERSION_1_8 126 | targetCompatibility JavaVersion.VERSION_1_8 127 | } 128 | 129 | defaultConfig { 130 | applicationId "com.example.reactnativetranscription" 131 | minSdkVersion rootProject.ext.minSdkVersion 132 | targetSdkVersion rootProject.ext.targetSdkVersion 133 | versionCode 1 134 | versionName "1.0" 135 | } 136 | splits { 137 | abi { 138 | reset() 139 | enable enableSeparateBuildPerCPUArchitecture 140 | universalApk false // If true, also generate a universal APK 141 | include "armeabi-v7a", "x86", "arm64-v8a", "x86_64" 142 | } 143 | } 144 | signingConfigs { 145 | debug { 146 | storeFile file('debug.keystore') 147 | storePassword 'android' 148 | keyAlias 'androiddebugkey' 149 | keyPassword 'android' 150 | } 151 | } 152 | buildTypes { 153 | debug { 154 | signingConfig signingConfigs.debug 155 | } 156 | release { 157 | // Caution! In production, you need to generate your own keystore file. 158 | // see https://facebook.github.io/react-native/docs/signed-apk-android. 159 | signingConfig signingConfigs.debug 160 | minifyEnabled enableProguardInReleaseBuilds 161 | proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro" 162 | } 163 | } 164 | // applicationVariants are e.g. debug, release 165 | applicationVariants.all { variant -> 166 | variant.outputs.each { output -> 167 | // For each separate APK per architecture, set a unique version code as described here: 168 | // https://developer.android.com/studio/build/configure-apk-splits.html 169 | def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4] 170 | def abi = output.getFilter(OutputFile.ABI) 171 | if (abi != null) { // null for the universal-debug, universal-release variants 172 | output.versionCodeOverride = 173 | versionCodes.get(abi) * 1048576 + defaultConfig.versionCode 174 | } 175 | 176 | } 177 | } 178 | 179 | packagingOptions { 180 | pickFirst "lib/armeabi-v7a/libc++_shared.so" 181 | pickFirst "lib/arm64-v8a/libc++_shared.so" 182 | pickFirst "lib/x86/libc++_shared.so" 183 | pickFirst "lib/x86_64/libc++_shared.so" 184 | } 185 | } 186 | 187 | dependencies { 188 | implementation fileTree(dir: "libs", include: ["*.jar"]) 189 | //noinspection GradleDynamicVersion 190 | implementation "com.facebook.react:react-native:+" // From node_modules 191 | 192 | 193 | implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0" 194 | debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") { 195 | exclude group:'com.facebook.fbjni' 196 | } 197 | debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") { 198 | exclude group:'com.facebook.flipper' 199 | } 200 | debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") { 201 | exclude group:'com.facebook.flipper' 202 | } 203 | 204 | if (enableHermes) { 205 | def hermesPath = "../../node_modules/hermes-engine/android/"; 206 | debugImplementation files(hermesPath + "hermes-debug.aar") 207 | releaseImplementation files(hermesPath + "hermes-release.aar") 208 | } else { 209 | implementation jscFlavor 210 | } 211 | 212 | implementation project(':reactnativetranscription') 213 | } 214 | 215 | // Run this once to be able to run the application with BUCK 216 | // puts all compile dependencies into folder libs for BUCK to use 217 | task copyDownloadableDepsToLibs(type: Copy) { 218 | from configurations.compile 219 | into 'libs' 220 | } 221 | 222 | apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project) 223 | -------------------------------------------------------------------------------- /example/android/app/debug.keystore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReLearnApp/react-native-transcription/8809e9ae01eca460ebf3e0184d77af961b3e39e2/example/android/app/debug.keystore -------------------------------------------------------------------------------- /example/android/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /usr/local/Cellar/android-sdk/24.3.3/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | -------------------------------------------------------------------------------- /example/android/app/src/debug/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/android/app/src/debug/java/com/example/reactnativetranscription/ReactNativeFlipper.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Facebook, Inc. and its affiliates. 3 | * 4 | *

This source code is licensed under the MIT license found in the LICENSE file in the root 5 | * directory of this source tree. 6 | */ 7 | package com.example.reactnativetranscription; 8 | 9 | import android.content.Context; 10 | import com.facebook.flipper.android.AndroidFlipperClient; 11 | import com.facebook.flipper.android.utils.FlipperUtils; 12 | import com.facebook.flipper.core.FlipperClient; 13 | import com.facebook.flipper.plugins.crashreporter.CrashReporterPlugin; 14 | import com.facebook.flipper.plugins.databases.DatabasesFlipperPlugin; 15 | import com.facebook.flipper.plugins.fresco.FrescoFlipperPlugin; 16 | import com.facebook.flipper.plugins.inspector.DescriptorMapping; 17 | import com.facebook.flipper.plugins.inspector.InspectorFlipperPlugin; 18 | import com.facebook.flipper.plugins.network.FlipperOkhttpInterceptor; 19 | import com.facebook.flipper.plugins.network.NetworkFlipperPlugin; 20 | import com.facebook.flipper.plugins.react.ReactFlipperPlugin; 21 | import com.facebook.flipper.plugins.sharedpreferences.SharedPreferencesFlipperPlugin; 22 | import com.facebook.react.ReactInstanceManager; 23 | import com.facebook.react.bridge.ReactContext; 24 | import com.facebook.react.modules.network.NetworkingModule; 25 | import okhttp3.OkHttpClient; 26 | 27 | public class ReactNativeFlipper { 28 | public static void initializeFlipper(Context context, ReactInstanceManager reactInstanceManager) { 29 | if (FlipperUtils.shouldEnableFlipper(context)) { 30 | final FlipperClient client = AndroidFlipperClient.getInstance(context); 31 | client.addPlugin(new InspectorFlipperPlugin(context, DescriptorMapping.withDefaults())); 32 | client.addPlugin(new ReactFlipperPlugin()); 33 | client.addPlugin(new DatabasesFlipperPlugin(context)); 34 | client.addPlugin(new SharedPreferencesFlipperPlugin(context)); 35 | client.addPlugin(CrashReporterPlugin.getInstance()); 36 | NetworkFlipperPlugin networkFlipperPlugin = new NetworkFlipperPlugin(); 37 | NetworkingModule.setCustomClientBuilder( 38 | new NetworkingModule.CustomClientBuilder() { 39 | @Override 40 | public void apply(OkHttpClient.Builder builder) { 41 | builder.addNetworkInterceptor(new FlipperOkhttpInterceptor(networkFlipperPlugin)); 42 | } 43 | }); 44 | client.addPlugin(networkFlipperPlugin); 45 | client.start(); 46 | // Fresco Plugin needs to ensure that ImagePipelineFactory is initialized 47 | // Hence we run if after all native modules have been initialized 48 | ReactContext reactContext = reactInstanceManager.getCurrentReactContext(); 49 | if (reactContext == null) { 50 | reactInstanceManager.addReactInstanceEventListener( 51 | new ReactInstanceManager.ReactInstanceEventListener() { 52 | @Override 53 | public void onReactContextInitialized(ReactContext reactContext) { 54 | reactInstanceManager.removeReactInstanceEventListener(this); 55 | reactContext.runOnNativeModulesQueueThread( 56 | new Runnable() { 57 | @Override 58 | public void run() { 59 | client.addPlugin(new FrescoFlipperPlugin()); 60 | } 61 | }); 62 | } 63 | }); 64 | } else { 65 | client.addPlugin(new FrescoFlipperPlugin()); 66 | } 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /example/android/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 17 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /example/android/app/src/main/java/com/example/reactnativetranscription/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.reactnativetranscription; 2 | 3 | import com.facebook.react.ReactActivity; 4 | 5 | public class MainActivity extends ReactActivity { 6 | 7 | /** 8 | * Returns the name of the main component registered from JavaScript. This is used to schedule 9 | * rendering of the component. 10 | */ 11 | @Override 12 | protected String getMainComponentName() { 13 | return "TranscriptionExample"; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /example/android/app/src/main/java/com/example/reactnativetranscription/MainApplication.java: -------------------------------------------------------------------------------- 1 | package com.example.reactnativetranscription; 2 | 3 | import android.app.Application; 4 | import android.content.Context; 5 | import com.facebook.react.PackageList; 6 | import com.facebook.react.ReactApplication; 7 | import com.facebook.react.ReactNativeHost; 8 | import com.facebook.react.ReactPackage; 9 | import com.facebook.react.ReactInstanceManager; 10 | import com.facebook.soloader.SoLoader; 11 | import java.lang.reflect.InvocationTargetException; 12 | import java.util.List; 13 | 14 | import com.reactnativetranscription.TranscriptionPackage; 15 | 16 | public class MainApplication extends Application implements ReactApplication { 17 | 18 | private final ReactNativeHost mReactNativeHost = 19 | new ReactNativeHost(this) { 20 | @Override 21 | public boolean getUseDeveloperSupport() { 22 | return BuildConfig.DEBUG; 23 | } 24 | 25 | @Override 26 | protected List getPackages() { 27 | @SuppressWarnings("UnnecessaryLocalVariable") 28 | List packages = new PackageList(this).getPackages(); 29 | // Packages that cannot be autolinked yet can be added manually here, for TranscriptionExample: 30 | // packages.add(new MyReactNativePackage()); 31 | packages.add(new TranscriptionPackage()); 32 | 33 | return packages; 34 | } 35 | 36 | @Override 37 | protected String getJSMainModuleName() { 38 | return "index"; 39 | } 40 | }; 41 | 42 | @Override 43 | public ReactNativeHost getReactNativeHost() { 44 | return mReactNativeHost; 45 | } 46 | 47 | @Override 48 | public void onCreate() { 49 | super.onCreate(); 50 | SoLoader.init(this, /* native exopackage */ false); 51 | initializeFlipper(this, getReactNativeHost().getReactInstanceManager()); // Remove this line if you don't want Flipper enabled 52 | } 53 | 54 | /** 55 | * Loads Flipper in React Native templates. 56 | * 57 | * @param context 58 | */ 59 | private static void initializeFlipper(Context context, ReactInstanceManager reactInstanceManager) { 60 | if (BuildConfig.DEBUG) { 61 | try { 62 | /* 63 | We use reflection here to pick up the class that initializes Flipper, 64 | since Flipper library is not available in release mode 65 | */ 66 | Class aClass = Class.forName("com.reactnativetranscriptionExample.ReactNativeFlipper"); 67 | aClass 68 | .getMethod("initializeFlipper", Context.class, ReactInstanceManager.class) 69 | .invoke(null, context, reactInstanceManager); 70 | } catch (ClassNotFoundException e) { 71 | e.printStackTrace(); 72 | } catch (NoSuchMethodException e) { 73 | e.printStackTrace(); 74 | } catch (IllegalAccessException e) { 75 | e.printStackTrace(); 76 | } catch (InvocationTargetException e) { 77 | e.printStackTrace(); 78 | } 79 | } 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReLearnApp/react-native-transcription/8809e9ae01eca460ebf3e0184d77af961b3e39e2/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReLearnApp/react-native-transcription/8809e9ae01eca460ebf3e0184d77af961b3e39e2/example/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReLearnApp/react-native-transcription/8809e9ae01eca460ebf3e0184d77af961b3e39e2/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReLearnApp/react-native-transcription/8809e9ae01eca460ebf3e0184d77af961b3e39e2/example/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReLearnApp/react-native-transcription/8809e9ae01eca460ebf3e0184d77af961b3e39e2/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReLearnApp/react-native-transcription/8809e9ae01eca460ebf3e0184d77af961b3e39e2/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReLearnApp/react-native-transcription/8809e9ae01eca460ebf3e0184d77af961b3e39e2/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReLearnApp/react-native-transcription/8809e9ae01eca460ebf3e0184d77af961b3e39e2/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReLearnApp/react-native-transcription/8809e9ae01eca460ebf3e0184d77af961b3e39e2/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReLearnApp/react-native-transcription/8809e9ae01eca460ebf3e0184d77af961b3e39e2/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Transcription Example 3 | 4 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /example/android/build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | ext { 5 | buildToolsVersion = "29.0.2" 6 | minSdkVersion = 22 7 | compileSdkVersion = 29 8 | targetSdkVersion = 29 9 | } 10 | repositories { 11 | google() 12 | jcenter() 13 | } 14 | dependencies { 15 | classpath('com.android.tools.build:gradle:4.0.1') 16 | 17 | // NOTE: Do not place your application dependencies here; they belong 18 | // in the individual module build.gradle files 19 | } 20 | } 21 | 22 | allprojects { 23 | repositories { 24 | mavenLocal() 25 | maven { 26 | // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm 27 | url("$rootDir/../node_modules/react-native/android") 28 | } 29 | maven { 30 | // Android JSC is installed from npm 31 | url("$rootDir/../node_modules/jsc-android/dist") 32 | } 33 | 34 | google() 35 | jcenter() 36 | maven { url 'https://www.jitpack.io' } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /example/android/gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true 19 | 20 | android.useAndroidX=true 21 | android.enableJetifier=true 22 | FLIPPER_VERSION=0.33.1 23 | -------------------------------------------------------------------------------- /example/android/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReLearnApp/react-native-transcription/8809e9ae01eca460ebf3e0184d77af961b3e39e2/example/android/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /example/android/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Thu Aug 20 23:16:57 EDT 2020 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip 7 | -------------------------------------------------------------------------------- /example/android/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # 4 | # Copyright 2015 the original author or authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | ## 21 | ## Gradle start up script for UN*X 22 | ## 23 | ############################################################################## 24 | 25 | # Attempt to set APP_HOME 26 | # Resolve links: $0 may be a link 27 | PRG="$0" 28 | # Need this for relative symlinks. 29 | while [ -h "$PRG" ] ; do 30 | ls=`ls -ld "$PRG"` 31 | link=`expr "$ls" : '.*-> \(.*\)$'` 32 | if expr "$link" : '/.*' > /dev/null; then 33 | PRG="$link" 34 | else 35 | PRG=`dirname "$PRG"`"/$link" 36 | fi 37 | done 38 | SAVED="`pwd`" 39 | cd "`dirname \"$PRG\"`/" >/dev/null 40 | APP_HOME="`pwd -P`" 41 | cd "$SAVED" >/dev/null 42 | 43 | APP_NAME="Gradle" 44 | APP_BASE_NAME=`basename "$0"` 45 | 46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 48 | 49 | # Use the maximum available, or set MAX_FD != -1 to use that value. 50 | MAX_FD="maximum" 51 | 52 | warn () { 53 | echo "$*" 54 | } 55 | 56 | die () { 57 | echo 58 | echo "$*" 59 | echo 60 | exit 1 61 | } 62 | 63 | # OS specific support (must be 'true' or 'false'). 64 | cygwin=false 65 | msys=false 66 | darwin=false 67 | nonstop=false 68 | case "`uname`" in 69 | CYGWIN* ) 70 | cygwin=true 71 | ;; 72 | Darwin* ) 73 | darwin=true 74 | ;; 75 | MINGW* ) 76 | msys=true 77 | ;; 78 | NONSTOP* ) 79 | nonstop=true 80 | ;; 81 | esac 82 | 83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 84 | 85 | # Determine the Java command to use to start the JVM. 86 | if [ -n "$JAVA_HOME" ] ; then 87 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 88 | # IBM's JDK on AIX uses strange locations for the executables 89 | JAVACMD="$JAVA_HOME/jre/sh/java" 90 | else 91 | JAVACMD="$JAVA_HOME/bin/java" 92 | fi 93 | if [ ! -x "$JAVACMD" ] ; then 94 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 95 | 96 | Please set the JAVA_HOME variable in your environment to match the 97 | location of your Java installation." 98 | fi 99 | else 100 | JAVACMD="java" 101 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 102 | 103 | Please set the JAVA_HOME variable in your environment to match the 104 | location of your Java installation." 105 | fi 106 | 107 | # Increase the maximum file descriptors if we can. 108 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 109 | MAX_FD_LIMIT=`ulimit -H -n` 110 | if [ $? -eq 0 ] ; then 111 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 112 | MAX_FD="$MAX_FD_LIMIT" 113 | fi 114 | ulimit -n $MAX_FD 115 | if [ $? -ne 0 ] ; then 116 | warn "Could not set maximum file descriptor limit: $MAX_FD" 117 | fi 118 | else 119 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 120 | fi 121 | fi 122 | 123 | # For Darwin, add options to specify how the application appears in the dock 124 | if $darwin; then 125 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 126 | fi 127 | 128 | # For Cygwin, switch paths to Windows format before running java 129 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then 130 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 131 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 132 | JAVACMD=`cygpath --unix "$JAVACMD"` 133 | 134 | # We build the pattern for arguments to be converted via cygpath 135 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 136 | SEP="" 137 | for dir in $ROOTDIRSRAW ; do 138 | ROOTDIRS="$ROOTDIRS$SEP$dir" 139 | SEP="|" 140 | done 141 | OURCYGPATTERN="(^($ROOTDIRS))" 142 | # Add a user-defined pattern to the cygpath arguments 143 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 144 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 145 | fi 146 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 147 | i=0 148 | for arg in "$@" ; do 149 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 150 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 151 | 152 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 153 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 154 | else 155 | eval `echo args$i`="\"$arg\"" 156 | fi 157 | i=$((i+1)) 158 | done 159 | case $i in 160 | (0) set -- ;; 161 | (1) set -- "$args0" ;; 162 | (2) set -- "$args0" "$args1" ;; 163 | (3) set -- "$args0" "$args1" "$args2" ;; 164 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 165 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 166 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 167 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 168 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 169 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 170 | esac 171 | fi 172 | 173 | # Escape application args 174 | save () { 175 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 176 | echo " " 177 | } 178 | APP_ARGS=$(save "$@") 179 | 180 | # Collect all arguments for the java command, following the shell quoting and substitution rules 181 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 182 | 183 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 184 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 185 | cd "$(dirname "$0")" 186 | fi 187 | 188 | exec "$JAVACMD" "$@" 189 | -------------------------------------------------------------------------------- /example/android/gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem http://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 33 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 34 | 35 | @rem Find java.exe 36 | if defined JAVA_HOME goto findJavaFromJavaHome 37 | 38 | set JAVA_EXE=java.exe 39 | %JAVA_EXE% -version >NUL 2>&1 40 | if "%ERRORLEVEL%" == "0" goto init 41 | 42 | echo. 43 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 44 | echo. 45 | echo Please set the JAVA_HOME variable in your environment to match the 46 | echo location of your Java installation. 47 | 48 | goto fail 49 | 50 | :findJavaFromJavaHome 51 | set JAVA_HOME=%JAVA_HOME:"=% 52 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 53 | 54 | if exist "%JAVA_EXE%" goto init 55 | 56 | echo. 57 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 58 | echo. 59 | echo Please set the JAVA_HOME variable in your environment to match the 60 | echo location of your Java installation. 61 | 62 | goto fail 63 | 64 | :init 65 | @rem Get command-line arguments, handling Windows variants 66 | 67 | if not "%OS%" == "Windows_NT" goto win9xME_args 68 | 69 | :win9xME_args 70 | @rem Slurp the command line arguments. 71 | set CMD_LINE_ARGS= 72 | set _SKIP=2 73 | 74 | :win9xME_args_slurp 75 | if "x%~1" == "x" goto execute 76 | 77 | set CMD_LINE_ARGS=%* 78 | 79 | :execute 80 | @rem Setup the command line 81 | 82 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 83 | 84 | @rem Execute Gradle 85 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 86 | 87 | :end 88 | @rem End local scope for the variables with windows NT shell 89 | if "%ERRORLEVEL%"=="0" goto mainEnd 90 | 91 | :fail 92 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 93 | rem the _cmd.exe /c_ return code! 94 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 95 | exit /b 1 96 | 97 | :mainEnd 98 | if "%OS%"=="Windows_NT" endlocal 99 | 100 | :omega 101 | -------------------------------------------------------------------------------- /example/android/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'TranscriptionExample' 2 | apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings) 3 | include ':app' 4 | 5 | include ':reactnativetranscription' 6 | project(':reactnativetranscription').projectDir = new File(rootProject.projectDir, '../../android') 7 | -------------------------------------------------------------------------------- /example/app.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "TranscriptionExample", 3 | "displayName": "Transcription Example" 4 | } 5 | -------------------------------------------------------------------------------- /example/babel.config.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | const pak = require('../package.json'); 3 | 4 | module.exports = { 5 | presets: ['module:metro-react-native-babel-preset'], 6 | plugins: [ 7 | [ 8 | 'module-resolver', 9 | { 10 | alias: { 11 | [pak.name]: path.join(__dirname, '..', pak.source), 12 | }, 13 | }, 14 | ], 15 | ], 16 | }; 17 | -------------------------------------------------------------------------------- /example/index.tsx: -------------------------------------------------------------------------------- 1 | import { AppRegistry } from 'react-native'; 2 | import App from './src/App'; 3 | import { name as appName } from './app.json'; 4 | 5 | AppRegistry.registerComponent(appName, () => App); 6 | -------------------------------------------------------------------------------- /example/ios/File.swift: -------------------------------------------------------------------------------- 1 | // 2 | // File.swift 3 | // TranscriptionExample 4 | // 5 | 6 | import Foundation 7 | -------------------------------------------------------------------------------- /example/ios/Podfile: -------------------------------------------------------------------------------- 1 | platform :ios, '13.5' 2 | #plugin 'cocoapods-user-defined-build-types' 3 | require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules' 4 | 5 | #enable_user_defined_build_types! 6 | #use_frameworks! 7 | 8 | 9 | target 'TranscriptionExample' do 10 | # Pods for TranscriptionExample 11 | pod 'FBLazyVector', :path => "../node_modules/react-native/Libraries/FBLazyVector" 12 | pod 'FBReactNativeSpec', :path => "../node_modules/react-native/Libraries/FBReactNativeSpec" 13 | pod 'RCTRequired', :path => "../node_modules/react-native/Libraries/RCTRequired" 14 | pod 'RCTTypeSafety', :path => "../node_modules/react-native/Libraries/TypeSafety" 15 | pod 'React', :path => '../node_modules/react-native/' 16 | pod 'React-Core', :path => '../node_modules/react-native/' 17 | pod 'React-CoreModules', :path => '../node_modules/react-native/React/CoreModules' 18 | pod 'React-Core/DevSupport', :path => '../node_modules/react-native/' 19 | pod 'React-RCTActionSheet', :path => '../node_modules/react-native/Libraries/ActionSheetIOS' 20 | pod 'React-RCTAnimation', :path => '../node_modules/react-native/Libraries/NativeAnimation' 21 | pod 'React-RCTBlob', :path => '../node_modules/react-native/Libraries/Blob' 22 | pod 'React-RCTImage', :path => '../node_modules/react-native/Libraries/Image' 23 | pod 'React-RCTLinking', :path => '../node_modules/react-native/Libraries/LinkingIOS' 24 | pod 'React-RCTNetwork', :path => '../node_modules/react-native/Libraries/Network' 25 | pod 'React-RCTSettings', :path => '../node_modules/react-native/Libraries/Settings' 26 | pod 'React-RCTText', :path => '../node_modules/react-native/Libraries/Text' 27 | pod 'React-RCTVibration', :path => '../node_modules/react-native/Libraries/Vibration' 28 | pod 'React-Core/RCTWebSocket', :path => '../node_modules/react-native/' 29 | 30 | pod 'React-cxxreact', :path => '../node_modules/react-native/ReactCommon/cxxreact' 31 | pod 'React-jsi', :path => '../node_modules/react-native/ReactCommon/jsi' 32 | pod 'React-jsiexecutor', :path => '../node_modules/react-native/ReactCommon/jsiexecutor' 33 | pod 'React-jsinspector', :path => '../node_modules/react-native/ReactCommon/jsinspector' 34 | pod 'ReactCommon/callinvoker', :path => "../node_modules/react-native/ReactCommon" 35 | pod 'ReactCommon/turbomodule/core', :path => "../node_modules/react-native/ReactCommon" 36 | pod 'Yoga', :path => '../node_modules/react-native/ReactCommon/yoga', :modular_headers => true 37 | 38 | pod 'DoubleConversion', :podspec => '../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec' 39 | pod 'glog', :podspec => '../node_modules/react-native/third-party-podspecs/glog.podspec' 40 | pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec' 41 | 42 | permissions_path = '../node_modules/react-native-permissions/ios' 43 | pod 'Permission-Microphone', :path => "#{permissions_path}/Microphone.podspec" 44 | pod 'Permission-SpeechRecognition', :path => "#{permissions_path}/SpeechRecognition.podspec" 45 | 46 | 47 | pod 'react-native-transcription', :path => '../..' 48 | 49 | use_native_modules! 50 | 51 | 52 | end 53 | -------------------------------------------------------------------------------- /example/ios/Podfile.lock: -------------------------------------------------------------------------------- 1 | PODS: 2 | - boost-for-react-native (1.63.0) 3 | - DoubleConversion (1.1.6) 4 | - FBLazyVector (0.62.2) 5 | - FBReactNativeSpec (0.62.2): 6 | - Folly (= 2018.10.22.00) 7 | - RCTRequired (= 0.62.2) 8 | - RCTTypeSafety (= 0.62.2) 9 | - React-Core (= 0.62.2) 10 | - React-jsi (= 0.62.2) 11 | - ReactCommon/turbomodule/core (= 0.62.2) 12 | - Folly (2018.10.22.00): 13 | - boost-for-react-native 14 | - DoubleConversion 15 | - Folly/Default (= 2018.10.22.00) 16 | - glog 17 | - Folly/Default (2018.10.22.00): 18 | - boost-for-react-native 19 | - DoubleConversion 20 | - glog 21 | - glog (0.3.5) 22 | - Permission-Microphone (2.1.5): 23 | - RNPermissions 24 | - Permission-SpeechRecognition (2.1.5): 25 | - RNPermissions 26 | - RCTRequired (0.62.2) 27 | - RCTTypeSafety (0.62.2): 28 | - FBLazyVector (= 0.62.2) 29 | - Folly (= 2018.10.22.00) 30 | - RCTRequired (= 0.62.2) 31 | - React-Core (= 0.62.2) 32 | - React (0.62.2): 33 | - React-Core (= 0.62.2) 34 | - React-Core/DevSupport (= 0.62.2) 35 | - React-Core/RCTWebSocket (= 0.62.2) 36 | - React-RCTActionSheet (= 0.62.2) 37 | - React-RCTAnimation (= 0.62.2) 38 | - React-RCTBlob (= 0.62.2) 39 | - React-RCTImage (= 0.62.2) 40 | - React-RCTLinking (= 0.62.2) 41 | - React-RCTNetwork (= 0.62.2) 42 | - React-RCTSettings (= 0.62.2) 43 | - React-RCTText (= 0.62.2) 44 | - React-RCTVibration (= 0.62.2) 45 | - React-Core (0.62.2): 46 | - Folly (= 2018.10.22.00) 47 | - glog 48 | - React-Core/Default (= 0.62.2) 49 | - React-cxxreact (= 0.62.2) 50 | - React-jsi (= 0.62.2) 51 | - React-jsiexecutor (= 0.62.2) 52 | - Yoga 53 | - React-Core/CoreModulesHeaders (0.62.2): 54 | - Folly (= 2018.10.22.00) 55 | - glog 56 | - React-Core/Default 57 | - React-cxxreact (= 0.62.2) 58 | - React-jsi (= 0.62.2) 59 | - React-jsiexecutor (= 0.62.2) 60 | - Yoga 61 | - React-Core/Default (0.62.2): 62 | - Folly (= 2018.10.22.00) 63 | - glog 64 | - React-cxxreact (= 0.62.2) 65 | - React-jsi (= 0.62.2) 66 | - React-jsiexecutor (= 0.62.2) 67 | - Yoga 68 | - React-Core/DevSupport (0.62.2): 69 | - Folly (= 2018.10.22.00) 70 | - glog 71 | - React-Core/Default (= 0.62.2) 72 | - React-Core/RCTWebSocket (= 0.62.2) 73 | - React-cxxreact (= 0.62.2) 74 | - React-jsi (= 0.62.2) 75 | - React-jsiexecutor (= 0.62.2) 76 | - React-jsinspector (= 0.62.2) 77 | - Yoga 78 | - React-Core/RCTActionSheetHeaders (0.62.2): 79 | - Folly (= 2018.10.22.00) 80 | - glog 81 | - React-Core/Default 82 | - React-cxxreact (= 0.62.2) 83 | - React-jsi (= 0.62.2) 84 | - React-jsiexecutor (= 0.62.2) 85 | - Yoga 86 | - React-Core/RCTAnimationHeaders (0.62.2): 87 | - Folly (= 2018.10.22.00) 88 | - glog 89 | - React-Core/Default 90 | - React-cxxreact (= 0.62.2) 91 | - React-jsi (= 0.62.2) 92 | - React-jsiexecutor (= 0.62.2) 93 | - Yoga 94 | - React-Core/RCTBlobHeaders (0.62.2): 95 | - Folly (= 2018.10.22.00) 96 | - glog 97 | - React-Core/Default 98 | - React-cxxreact (= 0.62.2) 99 | - React-jsi (= 0.62.2) 100 | - React-jsiexecutor (= 0.62.2) 101 | - Yoga 102 | - React-Core/RCTImageHeaders (0.62.2): 103 | - Folly (= 2018.10.22.00) 104 | - glog 105 | - React-Core/Default 106 | - React-cxxreact (= 0.62.2) 107 | - React-jsi (= 0.62.2) 108 | - React-jsiexecutor (= 0.62.2) 109 | - Yoga 110 | - React-Core/RCTLinkingHeaders (0.62.2): 111 | - Folly (= 2018.10.22.00) 112 | - glog 113 | - React-Core/Default 114 | - React-cxxreact (= 0.62.2) 115 | - React-jsi (= 0.62.2) 116 | - React-jsiexecutor (= 0.62.2) 117 | - Yoga 118 | - React-Core/RCTNetworkHeaders (0.62.2): 119 | - Folly (= 2018.10.22.00) 120 | - glog 121 | - React-Core/Default 122 | - React-cxxreact (= 0.62.2) 123 | - React-jsi (= 0.62.2) 124 | - React-jsiexecutor (= 0.62.2) 125 | - Yoga 126 | - React-Core/RCTSettingsHeaders (0.62.2): 127 | - Folly (= 2018.10.22.00) 128 | - glog 129 | - React-Core/Default 130 | - React-cxxreact (= 0.62.2) 131 | - React-jsi (= 0.62.2) 132 | - React-jsiexecutor (= 0.62.2) 133 | - Yoga 134 | - React-Core/RCTTextHeaders (0.62.2): 135 | - Folly (= 2018.10.22.00) 136 | - glog 137 | - React-Core/Default 138 | - React-cxxreact (= 0.62.2) 139 | - React-jsi (= 0.62.2) 140 | - React-jsiexecutor (= 0.62.2) 141 | - Yoga 142 | - React-Core/RCTVibrationHeaders (0.62.2): 143 | - Folly (= 2018.10.22.00) 144 | - glog 145 | - React-Core/Default 146 | - React-cxxreact (= 0.62.2) 147 | - React-jsi (= 0.62.2) 148 | - React-jsiexecutor (= 0.62.2) 149 | - Yoga 150 | - React-Core/RCTWebSocket (0.62.2): 151 | - Folly (= 2018.10.22.00) 152 | - glog 153 | - React-Core/Default (= 0.62.2) 154 | - React-cxxreact (= 0.62.2) 155 | - React-jsi (= 0.62.2) 156 | - React-jsiexecutor (= 0.62.2) 157 | - Yoga 158 | - React-CoreModules (0.62.2): 159 | - FBReactNativeSpec (= 0.62.2) 160 | - Folly (= 2018.10.22.00) 161 | - RCTTypeSafety (= 0.62.2) 162 | - React-Core/CoreModulesHeaders (= 0.62.2) 163 | - React-RCTImage (= 0.62.2) 164 | - ReactCommon/turbomodule/core (= 0.62.2) 165 | - React-cxxreact (0.62.2): 166 | - boost-for-react-native (= 1.63.0) 167 | - DoubleConversion 168 | - Folly (= 2018.10.22.00) 169 | - glog 170 | - React-jsinspector (= 0.62.2) 171 | - React-jsi (0.62.2): 172 | - boost-for-react-native (= 1.63.0) 173 | - DoubleConversion 174 | - Folly (= 2018.10.22.00) 175 | - glog 176 | - React-jsi/Default (= 0.62.2) 177 | - React-jsi/Default (0.62.2): 178 | - boost-for-react-native (= 1.63.0) 179 | - DoubleConversion 180 | - Folly (= 2018.10.22.00) 181 | - glog 182 | - React-jsiexecutor (0.62.2): 183 | - DoubleConversion 184 | - Folly (= 2018.10.22.00) 185 | - glog 186 | - React-cxxreact (= 0.62.2) 187 | - React-jsi (= 0.62.2) 188 | - React-jsinspector (0.62.2) 189 | - react-native-background-downloader (2.3.4): 190 | - React 191 | - react-native-transcription (0.1.0): 192 | - React 193 | - React-RCTActionSheet (0.62.2): 194 | - React-Core/RCTActionSheetHeaders (= 0.62.2) 195 | - React-RCTAnimation (0.62.2): 196 | - FBReactNativeSpec (= 0.62.2) 197 | - Folly (= 2018.10.22.00) 198 | - RCTTypeSafety (= 0.62.2) 199 | - React-Core/RCTAnimationHeaders (= 0.62.2) 200 | - ReactCommon/turbomodule/core (= 0.62.2) 201 | - React-RCTBlob (0.62.2): 202 | - FBReactNativeSpec (= 0.62.2) 203 | - Folly (= 2018.10.22.00) 204 | - React-Core/RCTBlobHeaders (= 0.62.2) 205 | - React-Core/RCTWebSocket (= 0.62.2) 206 | - React-jsi (= 0.62.2) 207 | - React-RCTNetwork (= 0.62.2) 208 | - ReactCommon/turbomodule/core (= 0.62.2) 209 | - React-RCTImage (0.62.2): 210 | - FBReactNativeSpec (= 0.62.2) 211 | - Folly (= 2018.10.22.00) 212 | - RCTTypeSafety (= 0.62.2) 213 | - React-Core/RCTImageHeaders (= 0.62.2) 214 | - React-RCTNetwork (= 0.62.2) 215 | - ReactCommon/turbomodule/core (= 0.62.2) 216 | - React-RCTLinking (0.62.2): 217 | - FBReactNativeSpec (= 0.62.2) 218 | - React-Core/RCTLinkingHeaders (= 0.62.2) 219 | - ReactCommon/turbomodule/core (= 0.62.2) 220 | - React-RCTNetwork (0.62.2): 221 | - FBReactNativeSpec (= 0.62.2) 222 | - Folly (= 2018.10.22.00) 223 | - RCTTypeSafety (= 0.62.2) 224 | - React-Core/RCTNetworkHeaders (= 0.62.2) 225 | - ReactCommon/turbomodule/core (= 0.62.2) 226 | - React-RCTSettings (0.62.2): 227 | - FBReactNativeSpec (= 0.62.2) 228 | - Folly (= 2018.10.22.00) 229 | - RCTTypeSafety (= 0.62.2) 230 | - React-Core/RCTSettingsHeaders (= 0.62.2) 231 | - ReactCommon/turbomodule/core (= 0.62.2) 232 | - React-RCTText (0.62.2): 233 | - React-Core/RCTTextHeaders (= 0.62.2) 234 | - React-RCTVibration (0.62.2): 235 | - FBReactNativeSpec (= 0.62.2) 236 | - Folly (= 2018.10.22.00) 237 | - React-Core/RCTVibrationHeaders (= 0.62.2) 238 | - ReactCommon/turbomodule/core (= 0.62.2) 239 | - ReactCommon/callinvoker (0.62.2): 240 | - DoubleConversion 241 | - Folly (= 2018.10.22.00) 242 | - glog 243 | - React-cxxreact (= 0.62.2) 244 | - ReactCommon/turbomodule/core (0.62.2): 245 | - DoubleConversion 246 | - Folly (= 2018.10.22.00) 247 | - glog 248 | - React-Core (= 0.62.2) 249 | - React-cxxreact (= 0.62.2) 250 | - React-jsi (= 0.62.2) 251 | - ReactCommon/callinvoker (= 0.62.2) 252 | - RNPermissions (2.1.5): 253 | - React 254 | - Yoga (1.14.0) 255 | 256 | DEPENDENCIES: 257 | - DoubleConversion (from `../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec`) 258 | - FBLazyVector (from `../node_modules/react-native/Libraries/FBLazyVector`) 259 | - FBReactNativeSpec (from `../node_modules/react-native/Libraries/FBReactNativeSpec`) 260 | - Folly (from `../node_modules/react-native/third-party-podspecs/Folly.podspec`) 261 | - glog (from `../node_modules/react-native/third-party-podspecs/glog.podspec`) 262 | - Permission-Microphone (from `../node_modules/react-native-permissions/ios/Microphone.podspec`) 263 | - Permission-SpeechRecognition (from `../node_modules/react-native-permissions/ios/SpeechRecognition.podspec`) 264 | - RCTRequired (from `../node_modules/react-native/Libraries/RCTRequired`) 265 | - RCTTypeSafety (from `../node_modules/react-native/Libraries/TypeSafety`) 266 | - React (from `../node_modules/react-native/`) 267 | - React-Core (from `../node_modules/react-native/`) 268 | - React-Core/DevSupport (from `../node_modules/react-native/`) 269 | - React-Core/RCTWebSocket (from `../node_modules/react-native/`) 270 | - React-CoreModules (from `../node_modules/react-native/React/CoreModules`) 271 | - React-cxxreact (from `../node_modules/react-native/ReactCommon/cxxreact`) 272 | - React-jsi (from `../node_modules/react-native/ReactCommon/jsi`) 273 | - React-jsiexecutor (from `../node_modules/react-native/ReactCommon/jsiexecutor`) 274 | - React-jsinspector (from `../node_modules/react-native/ReactCommon/jsinspector`) 275 | - react-native-background-downloader (from `../node_modules/react-native-background-downloader`) 276 | - react-native-transcription (from `../..`) 277 | - React-RCTActionSheet (from `../node_modules/react-native/Libraries/ActionSheetIOS`) 278 | - React-RCTAnimation (from `../node_modules/react-native/Libraries/NativeAnimation`) 279 | - React-RCTBlob (from `../node_modules/react-native/Libraries/Blob`) 280 | - React-RCTImage (from `../node_modules/react-native/Libraries/Image`) 281 | - React-RCTLinking (from `../node_modules/react-native/Libraries/LinkingIOS`) 282 | - React-RCTNetwork (from `../node_modules/react-native/Libraries/Network`) 283 | - React-RCTSettings (from `../node_modules/react-native/Libraries/Settings`) 284 | - React-RCTText (from `../node_modules/react-native/Libraries/Text`) 285 | - React-RCTVibration (from `../node_modules/react-native/Libraries/Vibration`) 286 | - ReactCommon/callinvoker (from `../node_modules/react-native/ReactCommon`) 287 | - ReactCommon/turbomodule/core (from `../node_modules/react-native/ReactCommon`) 288 | - RNPermissions (from `../node_modules/react-native-permissions`) 289 | - Yoga (from `../node_modules/react-native/ReactCommon/yoga`) 290 | 291 | SPEC REPOS: 292 | trunk: 293 | - boost-for-react-native 294 | 295 | EXTERNAL SOURCES: 296 | DoubleConversion: 297 | :podspec: "../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec" 298 | FBLazyVector: 299 | :path: "../node_modules/react-native/Libraries/FBLazyVector" 300 | FBReactNativeSpec: 301 | :path: "../node_modules/react-native/Libraries/FBReactNativeSpec" 302 | Folly: 303 | :podspec: "../node_modules/react-native/third-party-podspecs/Folly.podspec" 304 | glog: 305 | :podspec: "../node_modules/react-native/third-party-podspecs/glog.podspec" 306 | Permission-Microphone: 307 | :path: "../node_modules/react-native-permissions/ios/Microphone.podspec" 308 | Permission-SpeechRecognition: 309 | :path: "../node_modules/react-native-permissions/ios/SpeechRecognition.podspec" 310 | RCTRequired: 311 | :path: "../node_modules/react-native/Libraries/RCTRequired" 312 | RCTTypeSafety: 313 | :path: "../node_modules/react-native/Libraries/TypeSafety" 314 | React: 315 | :path: "../node_modules/react-native/" 316 | React-Core: 317 | :path: "../node_modules/react-native/" 318 | React-CoreModules: 319 | :path: "../node_modules/react-native/React/CoreModules" 320 | React-cxxreact: 321 | :path: "../node_modules/react-native/ReactCommon/cxxreact" 322 | React-jsi: 323 | :path: "../node_modules/react-native/ReactCommon/jsi" 324 | React-jsiexecutor: 325 | :path: "../node_modules/react-native/ReactCommon/jsiexecutor" 326 | React-jsinspector: 327 | :path: "../node_modules/react-native/ReactCommon/jsinspector" 328 | react-native-background-downloader: 329 | :path: "../node_modules/react-native-background-downloader" 330 | react-native-transcription: 331 | :path: "../.." 332 | React-RCTActionSheet: 333 | :path: "../node_modules/react-native/Libraries/ActionSheetIOS" 334 | React-RCTAnimation: 335 | :path: "../node_modules/react-native/Libraries/NativeAnimation" 336 | React-RCTBlob: 337 | :path: "../node_modules/react-native/Libraries/Blob" 338 | React-RCTImage: 339 | :path: "../node_modules/react-native/Libraries/Image" 340 | React-RCTLinking: 341 | :path: "../node_modules/react-native/Libraries/LinkingIOS" 342 | React-RCTNetwork: 343 | :path: "../node_modules/react-native/Libraries/Network" 344 | React-RCTSettings: 345 | :path: "../node_modules/react-native/Libraries/Settings" 346 | React-RCTText: 347 | :path: "../node_modules/react-native/Libraries/Text" 348 | React-RCTVibration: 349 | :path: "../node_modules/react-native/Libraries/Vibration" 350 | ReactCommon: 351 | :path: "../node_modules/react-native/ReactCommon" 352 | RNPermissions: 353 | :path: "../node_modules/react-native-permissions" 354 | Yoga: 355 | :path: "../node_modules/react-native/ReactCommon/yoga" 356 | 357 | SPEC CHECKSUMS: 358 | boost-for-react-native: 39c7adb57c4e60d6c5479dd8623128eb5b3f0f2c 359 | DoubleConversion: 5805e889d232975c086db112ece9ed034df7a0b2 360 | FBLazyVector: 4aab18c93cd9546e4bfed752b4084585eca8b245 361 | FBReactNativeSpec: 5465d51ccfeecb7faa12f9ae0024f2044ce4044e 362 | Folly: 30e7936e1c45c08d884aa59369ed951a8e68cf51 363 | glog: 1f3da668190260b06b429bb211bfbee5cd790c28 364 | Permission-Microphone: af45e35013788b52eecf3cd8f13185c4b6f7bff7 365 | Permission-SpeechRecognition: 844dc75f7165ff00bc0714bedd1c2bd42d6fa076 366 | RCTRequired: cec6a34b3ac8a9915c37e7e4ad3aa74726ce4035 367 | RCTTypeSafety: 93006131180074cffa227a1075802c89a49dd4ce 368 | React: 29a8b1a02bd764fb7644ef04019270849b9a7ac3 369 | React-Core: b12bffb3f567fdf99510acb716ef1abd426e0e05 370 | React-CoreModules: 4a9b87bbe669d6c3173c0132c3328e3b000783d0 371 | React-cxxreact: e65f9c2ba0ac5be946f53548c1aaaee5873a8103 372 | React-jsi: b6dc94a6a12ff98e8877287a0b7620d365201161 373 | React-jsiexecutor: 1540d1c01bb493ae3124ed83351b1b6a155db7da 374 | React-jsinspector: 512e560d0e985d0e8c479a54a4e5c147a9c83493 375 | react-native-background-downloader: f33bf10a731164e272c9101254f63c74b8dc09f9 376 | react-native-transcription: 9b18433b5abcc422492ef8db8ef86348788485e3 377 | React-RCTActionSheet: f41ea8a811aac770e0cc6e0ad6b270c644ea8b7c 378 | React-RCTAnimation: 49ab98b1c1ff4445148b72a3d61554138565bad0 379 | React-RCTBlob: a332773f0ebc413a0ce85942a55b064471587a71 380 | React-RCTImage: e70be9b9c74fe4e42d0005f42cace7981c994ac3 381 | React-RCTLinking: c1b9739a88d56ecbec23b7f63650e44672ab2ad2 382 | React-RCTNetwork: 73138b6f45e5a2768ad93f3d57873c2a18d14b44 383 | React-RCTSettings: 6e3738a87e21b39a8cb08d627e68c44acf1e325a 384 | React-RCTText: fae545b10cfdb3d247c36c56f61a94cfd6dba41d 385 | React-RCTVibration: 4356114dbcba4ce66991096e51a66e61eda51256 386 | ReactCommon: ed4e11d27609d571e7eee8b65548efc191116eb3 387 | RNPermissions: 1888705aebcc81714efa5dbff94351e4388ae012 388 | Yoga: 3ebccbdd559724312790e7742142d062476b698e 389 | 390 | PODFILE CHECKSUM: 50cb54caa0890fdfd9108ef15113d65bf6a90ff8 391 | 392 | COCOAPODS: 1.9.3 393 | -------------------------------------------------------------------------------- /example/ios/TranscriptionExample-Bridging-Header.h: -------------------------------------------------------------------------------- 1 | // 2 | // Use this file to import your target's public headers that you would like to expose to Swift. 3 | // 4 | -------------------------------------------------------------------------------- /example/ios/TranscriptionExample.xcodeproj/xcshareddata/xcschemes/TranscriptionExample.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 29 | 35 | 36 | 37 | 38 | 39 | 44 | 45 | 51 | 52 | 53 | 54 | 55 | 56 | 66 | 68 | 74 | 75 | 76 | 77 | 81 | 82 | 83 | 84 | 90 | 92 | 98 | 99 | 100 | 101 | 103 | 104 | 107 | 108 | 109 | -------------------------------------------------------------------------------- /example/ios/TranscriptionExample.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /example/ios/TranscriptionExample.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/ios/TranscriptionExample/AppDelegate.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Facebook, Inc. and its affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #import 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (nonatomic, strong) UIWindow *window; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /example/ios/TranscriptionExample/AppDelegate.m: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Facebook, Inc. and its affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #import "AppDelegate.h" 9 | 10 | #import 11 | #import 12 | #import 13 | 14 | 15 | 16 | @implementation AppDelegate 17 | 18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 19 | { 20 | 21 | RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions]; 22 | RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge 23 | moduleName:@"TranscriptionExample" 24 | initialProperties:nil]; 25 | 26 | rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1]; 27 | 28 | self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; 29 | UIViewController *rootViewController = [UIViewController new]; 30 | rootViewController.view = rootView; 31 | self.window.rootViewController = rootViewController; 32 | [self.window makeKeyAndVisible]; 33 | return YES; 34 | } 35 | 36 | - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge 37 | { 38 | #if DEBUG 39 | return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil]; 40 | #else 41 | return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"]; 42 | #endif 43 | } 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /example/ios/TranscriptionExample/Base.lproj/LaunchScreen.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 21 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /example/ios/TranscriptionExample/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /example/ios/TranscriptionExample/Images.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /example/ios/TranscriptionExample/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleDisplayName 8 | Transcription Example 9 | CFBundleExecutable 10 | $(EXECUTABLE_NAME) 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | $(PRODUCT_NAME) 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1 25 | LSRequiresIPhoneOS 26 | 27 | NSAppTransportSecurity 28 | 29 | NSAllowsArbitraryLoads 30 | 31 | NSExceptionDomains 32 | 33 | localhost 34 | 35 | NSExceptionAllowsInsecureHTTPLoads 36 | 37 | 38 | 39 | 40 | NSLocationWhenInUseUsageDescription 41 | 42 | UILaunchStoryboardName 43 | LaunchScreen 44 | UIRequiredDeviceCapabilities 45 | 46 | armv7 47 | 48 | UISupportedInterfaceOrientations 49 | 50 | UIInterfaceOrientationPortrait 51 | UIInterfaceOrientationLandscapeLeft 52 | UIInterfaceOrientationLandscapeRight 53 | 54 | UIViewControllerBasedStatusBarAppearance 55 | 56 | NSMicrophoneUsageDescription 57 | The example uses your mic to transcribe and record text 58 | NSSpeechRecognitionUsageDescription 59 | Might use SFSpeechRecognizer for live transcription. 60 | 61 | 62 | -------------------------------------------------------------------------------- /example/ios/TranscriptionExample/main.m: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Facebook, Inc. and its affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #import 9 | 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /example/metro.config.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | const blacklist = require('metro-config/src/defaults/blacklist'); 3 | const escape = require('escape-string-regexp'); 4 | const pak = require('../package.json'); 5 | 6 | const root = path.resolve(__dirname, '..'); 7 | 8 | const modules = Object.keys({ 9 | ...pak.peerDependencies, 10 | }); 11 | 12 | module.exports = { 13 | projectRoot: __dirname, 14 | watchFolders: [root], 15 | 16 | // We need to make sure that only one version is loaded for peerDependencies 17 | // So we blacklist them at the root, and alias them to the versions in example's node_modules 18 | resolver: { 19 | blacklistRE: blacklist( 20 | modules.map( 21 | (m) => 22 | new RegExp(`^${escape(path.join(root, 'node_modules', m))}\\/.*$`) 23 | ) 24 | ), 25 | 26 | extraNodeModules: modules.reduce((acc, name) => { 27 | acc[name] = path.join(__dirname, 'node_modules', name); 28 | return acc; 29 | }, {}), 30 | }, 31 | 32 | transformer: { 33 | getTransformOptions: async () => ({ 34 | transform: { 35 | experimentalImportSupport: false, 36 | inlineRequires: true, 37 | }, 38 | }), 39 | }, 40 | }; 41 | -------------------------------------------------------------------------------- /example/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-native-transcription-example", 3 | "description": "Example app for react-native-transcription", 4 | "version": "0.0.1", 5 | "private": true, 6 | "scripts": { 7 | "android": "react-native run-android", 8 | "ios": "react-native run-ios", 9 | "start": "react-native start" 10 | }, 11 | "dependencies": { 12 | "react": "16.11.0", 13 | "react-native": "0.62.2", 14 | "react-native-background-downloader": "^2.3.4", 15 | "react-native-permissions": "^2.1.5", 16 | "react-native-progress": "^4.1.2" 17 | }, 18 | "devDependencies": { 19 | "@babel/core": "^7.9.6", 20 | "@babel/runtime": "^7.9.6", 21 | "babel-plugin-module-resolver": "^4.0.0", 22 | "metro-react-native-babel-preset": "^0.59.0" 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /example/src/App.js: -------------------------------------------------------------------------------- 1 | import * as React from 'react'; 2 | import { NativeEventEmitter, StyleSheet, View, Text, Button } from 'react-native'; 3 | import Transcription from 'react-native-transcription'; 4 | import { check, PERMISSIONS, RESULTS, request } from 'react-native-permissions'; 5 | import RNBackgroundDownloader from 'react-native-background-downloader'; 6 | import * as Progress from 'react-native-progress'; 7 | 8 | export default class App extends React.Component { 9 | constructor(props) { 10 | super(props); 11 | this.state = { 12 | result: "Download the model files then tap start." 13 | }// Don't call this.setState() here! 14 | //console.log("Multiply") 15 | //Transcription.multiply(4, 5).then(result => console.log(result)) 16 | 17 | let lostTasks = RNBackgroundDownloader.checkForExistingDownloads().then((lostTasks) => { 18 | for (let task of lostTasks) { 19 | console.log(`Task ${task.id} was found!`); 20 | task.progress((percent) => { 21 | console.log(`Downloaded: ${percent * 100}%`); 22 | }).done(() => { 23 | console.log('Downlaod is done!'); 24 | }).error((error) => { 25 | console.log('Download canceled due to error: ', error); 26 | }); 27 | } 28 | }); 29 | 30 | 31 | check(PERMISSIONS.IOS.MICROPHONE) 32 | .then((result) => { 33 | switch (result) { 34 | case RESULTS.UNAVAILABLE: 35 | console.log( 36 | 'This feature is not available (on this device / in this context)', 37 | ); 38 | break; 39 | case RESULTS.DENIED: 40 | console.log( 41 | 'The permission has not been requested / is denied but requestable', 42 | ); 43 | request(PERMISSIONS.IOS.MICROPHONE); 44 | break; 45 | case RESULTS.GRANTED: 46 | console.log('The permission is granted'); 47 | break; 48 | case RESULTS.BLOCKED: 49 | console.log('The permission is denied and not requestable anymore'); 50 | break; 51 | } 52 | }) 53 | .catch((error) => { 54 | // … 55 | }); 56 | 57 | check(PERMISSIONS.ANDROID.RECORD_AUDIO) 58 | .then((result) => { 59 | switch (result) { 60 | case RESULTS.UNAVAILABLE: 61 | console.log( 62 | 'This feature is not available (on this device / in this context)', 63 | ); 64 | break; 65 | case RESULTS.DENIED: 66 | console.log( 67 | 'The permission has not been requested / is denied but requestable', 68 | ); 69 | console.log("Requesting") 70 | request(PERMISSIONS.ANDROID.RECORD_AUDIO); 71 | break; 72 | case RESULTS.GRANTED: 73 | console.log('The permission is granted'); 74 | break; 75 | case RESULTS.BLOCKED: 76 | console.log('The permission is denied and not requestable anymore'); 77 | break; 78 | } 79 | }) 80 | .catch((error) => { 81 | // … 82 | }); 83 | 84 | 85 | } 86 | 87 | componentDidMount() { 88 | 89 | console.log("URI: " + RNBackgroundDownloader.directories.documents); 90 | 91 | TranscriptEvents = new NativeEventEmitter(Transcription); 92 | 93 | this.transcribeUnsubscribe1 = TranscriptEvents.addListener("onRecordingChange", res => { 94 | console.log("onRecordingChange event", res); 95 | var transcription = ""; 96 | for(word in res.words){ 97 | transcription = (transcription + res.words[word] + " "); 98 | } 99 | this.setState({ result: transcription}); 100 | }); 101 | this.transcribeUnsubscribe1 = TranscriptEvents.addListener("onRecordingCompletion", res => { 102 | console.log("onRecordingCompletion event", res); 103 | var transcription = ""; 104 | for(word in res.words){ 105 | transcription = (transcription + res.words[word] + " "); 106 | } 107 | this.setState({ result: transcription}); 108 | }); 109 | this.transcribeUnsubscribe1 = TranscriptEvents.addListener("onWavTranscribed", res => { 110 | console.log("onWavTranscribed event", res); 111 | var transcription = ""; 112 | for(word in res.words){ 113 | transcription = (transcription + res.words[word] + " "); 114 | } 115 | this.setState({ result: transcription}); 116 | }); 117 | } 118 | 119 | startModelDownloads() { 120 | let modelTask = RNBackgroundDownloader.download({ 121 | id: 'model', 122 | url: 'https://github.com/mozilla/DeepSpeech/releases/download/v0.9.3/deepspeech-0.9.3-models.tflite', 123 | destination: `${RNBackgroundDownloader.directories.documents}/deepspeech-0.9.3-models.tflite` 124 | }).begin((expectedBytes) => { 125 | console.log(`Going to download ${expectedBytes} bytes!`); 126 | }).progress((percent) => { 127 | console.log(`Downloaded: ${percent * 100}%`); 128 | this.setState({ 129 | modelProgress: percent 130 | }) 131 | }).done(() => { 132 | console.log('Download is done!'); 133 | this.setState({ 134 | modelProgress: 0 135 | }) 136 | }).error((error) => { 137 | console.log('Download canceled due to error: ', error); 138 | }); 139 | 140 | 141 | let scorerTask = RNBackgroundDownloader.download({ 142 | id: 'scorer', 143 | url: 'https://github.com/mozilla/DeepSpeech/releases/download/v0.9.3/deepspeech-0.9.3-models.scorer', 144 | destination: `${RNBackgroundDownloader.directories.documents}/deepspeech-0.9.3-models.scorer` 145 | }).begin((expectedBytes) => { 146 | console.log(`Going to download ${expectedBytes} bytes!`); 147 | }).progress((percent) => { 148 | console.log(`Downloaded: ${percent * 100}%`); 149 | this.setState({ 150 | scorerProgress: percent 151 | }) 152 | }).done(() => { 153 | console.log('Download is done!'); 154 | this.setState({ 155 | scorerProgress: 0 156 | }) 157 | }).error((error) => { 158 | console.log('Download canceled due to error: ', error); 159 | }); 160 | 161 | let wavTask = RNBackgroundDownloader.download({ 162 | id: 'wav', 163 | url: 'https://www.ee.columbia.edu/~dpwe/sounds/mr/spkr0.wav', 164 | destination: `${RNBackgroundDownloader.directories.documents}/test.wav` 165 | }).begin((expectedBytes) => { 166 | console.log(`Going to download ${expectedBytes} bytes!`); 167 | }).progress((percent) => { 168 | console.log(`Downloaded: ${percent * 100}%`); 169 | this.setState({ 170 | wavProgress: percent 171 | }) 172 | }).done(() => { 173 | console.log('Download is done!'); 174 | this.setState({ 175 | wavProgress: 0 176 | }) 177 | }).error((error) => { 178 | console.log('Download canceled due to error: ', error); 179 | }); 180 | 181 | } 182 | 183 | render() { 184 | return ( 185 | 186 | Result: {this.state.result} 187 |