-
Notifications
You must be signed in to change notification settings - Fork 14
Feature/speech to text #82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
5b54191
add speech to text support
g4rb4g3 30e4419
Merge remote-tracking branch 'origin/master' into feature/speech-to-text
g4rb4g3 15b2929
add Android Auto car mic STT
g4rb4g3 c67848a
chore(react-native-autoplay): bump version to 0.4.2 [skip ci]
5a1560a
Merge remote-tracking branch 'origin/master' into feature/speech-to-text
g4rb4g3 f6708b1
fix merge errors
g4rb4g3 7f2837b
lint
g4rb4g3 98b0559
Merge remote-tracking branch 'origin/master' into feature/speech-to-text
g4rb4g3 a980b8c
add language parameter for speech recognizer, always fulfil promise w…
g4rb4g3 5add292
bump
g4rb4g3 7c744fc
update readme on how to use expo-font
g4rb4g3 cca775e
Merge remote-tracking branch 'origin/master' into feature/speech-to-text
g4rb4g3 17c6f3c
Merge remote-tracking branch 'origin/master' into feature/speech-to-text
g4rb4g3 dcf9337
bump
g4rb4g3 32858c5
nitrogen
g4rb4g3 c6a780d
bump
g4rb4g3 32bab2c
fix: tap not locking when updating samples
g4rb4g3 6e3a72f
cr fixes
g4rb4g3 2f69374
cr fixes
g4rb4g3 cd6f7bb
fall back to pcm on stt error
g4rb4g3 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
...ay/android/src/main/java/com/margelo/nitro/swe/iternio/reactnativeautoplay/HybridVoice.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| package com.margelo.nitro.swe.iternio.reactnativeautoplay | ||
|
|
||
| import android.content.pm.PackageManager | ||
| import android.os.Build | ||
| import androidx.core.content.ContextCompat | ||
| import com.facebook.react.modules.core.PermissionAwareActivity | ||
| import com.facebook.react.modules.core.PermissionListener | ||
| import com.margelo.nitro.NitroModules | ||
| import com.margelo.nitro.core.Promise | ||
| import kotlinx.coroutines.suspendCancellableCoroutine | ||
| import kotlin.coroutines.resume | ||
|
|
||
| class HybridVoice : HybridVoiceSpec() { | ||
| @Volatile | ||
| private var voiceInputManager: VoiceInputManager? = null | ||
|
|
||
| override fun hasVoiceInputPermission(): Boolean { | ||
| return VoiceInputManager.hasVoiceInputPermission() | ||
| } | ||
|
|
||
| override fun requestVoiceInputPermission(): Promise<Boolean> { | ||
| return Promise.async { | ||
| if (hasVoiceInputPermission()) { | ||
| return@async true | ||
| } | ||
|
|
||
| val carContext = AndroidAutoSession.getRootContext() | ||
|
|
||
| if (carContext != null) { | ||
| suspendCancellableCoroutine { cont -> | ||
| carContext.requestPermissions( | ||
| listOf(android.Manifest.permission.RECORD_AUDIO) | ||
| ) { approved, _ -> | ||
| cont.resume(approved.contains(android.Manifest.permission.RECORD_AUDIO)) | ||
| } | ||
| } | ||
| } else { | ||
| val context = NitroModules.applicationContext ?: return@async false | ||
| val activity = | ||
| context.currentActivity as? PermissionAwareActivity ?: return@async false | ||
| val code = (Math.random() * 10000).toInt() | ||
|
|
||
| suspendCancellableCoroutine { cont -> | ||
| activity.requestPermissions( | ||
| arrayOf(android.Manifest.permission.RECORD_AUDIO), | ||
| code, | ||
| PermissionListener { requestCode, _, grantResults -> | ||
| if (requestCode != code) { | ||
| return@PermissionListener false | ||
| } | ||
| cont.resume( | ||
| grantResults.isNotEmpty() && | ||
| grantResults.first() == PackageManager.PERMISSION_GRANTED | ||
| ) | ||
| true | ||
| } | ||
| ) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| override fun startVoiceInput( | ||
| silenceThresholdMs: Double?, | ||
| maxDurationMs: Double?, | ||
| listeningText: String?, | ||
| preferSpeechToText: Boolean?, | ||
| onChunk: ((chunk: VoiceInputChunk) -> Unit)?, | ||
| language: String? | ||
| ): Promise<VoiceInputResult> { | ||
| return Promise.async { | ||
| if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { | ||
| throw UnsupportedOperationException("startVoiceInput requires at least API level ${Build.VERSION_CODES.O}") | ||
| } | ||
|
|
||
| val manager = VoiceInputManager(AndroidAutoSession.getRootContext()) | ||
| voiceInputManager = manager | ||
|
|
||
| try { | ||
| manager.start( | ||
| silenceThresholdMs = silenceThresholdMs?.toLong() ?: 1_500L, | ||
| maxDurationMs = maxDurationMs?.toLong() ?: 10_000L, | ||
| preferSpeechToText = preferSpeechToText ?: false, | ||
| onChunk = onChunk, | ||
| language = language | ||
| ) | ||
| } finally { | ||
| voiceInputManager = null | ||
| manager.dispose() | ||
| } | ||
| } | ||
| } | ||
|
|
||
| override fun stopVoiceInput() { | ||
| voiceInputManager?.stop() | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just minor cosmetics, but for consistency you could use the same code style as in
AutoTemplate.ts-> requestVoiceInputPermission.then(() => ...)