Skip to content

rowntreerob/Google-speech-Opus-Recorder

Repository files navigation

Google-speech-Opus-Recorder

Recognize speech using cloud speech while also recording audio output file(opus-codec). Samples from 2 other git libs combined as one project.

Add audio Record to Cloud Speech API

how and what and why?

This sample brings into the Speech-recognizer, an additional lib project that actually records from the mic to Opus file during speech recognition. When the orig. recognizer API consumes the bytes obtained from the microphone/AudioRecord, send a copy of the bytes to ALSO be consumed by an instance of 'OpusTools' from the new library project.

Many have asked how Google Keep app was able to do both ( recognizer AND audio-file-out ). Many have asked how to recognize speech AND record audio at the same time.

How would it be useful?

It shows the basic API-Speech and encoderLib requirements for simultaneous recorder And Recognizer. It does not persist to cloud like it should. It only writes to EXT Storage like the project from which it was cloned. PULL reqs honored there.

Integration Details - making the 2 projects work by revising Speech API to know about 'OpusLib'

clone orig. recorder class so that it calls an OpusEnc object from the Toolslib that can encode PCM16 to Opus.

add gradle dependency for 'top.oply.opuslib:opuslib:1.0.2'

If you want the details (JNI , codecs) from the opus project you can import just the 'opuslib' directory as a Module and alter build.gradle and settings.gradle to process the imported module. Comment out the 'top.oply.lpuslib... ' dependency if you import the opuslib module.

additional permissions : [ .WRITE_EXTERNAL_STORAGE", .MOUNT_UNMOUNT_FILESYSTEMS" ]

Output files will be in "/storage/emulated/0/OPlayer/"

extra callback from the fragment to MAIN in order to stop the added service(opusLib) when the Fragment ends the recognizer

###install clone this module and then do as instructed in the orig. project below... paying close attention to the part on "Enable the Google speech api for your project". Verify you have your own 'credential.json' file obtain from the google cloud api console and that you locate this file at app/src/main/res/raw/credential.json

In that section you must download from Google api console the file=credential.json and copy that download to ./app/res/raw

./gradlew clean assembleDebug installDevDebug

look to the launcher for "Speech"

runtime logcat

Original Google Cloud Speech API examples

This directory contains Android example that uses the Google Cloud Speech API.

Prerequisites

Enable the Speech API

If you have not already done so, enable the Google Speech API for your project. You must be whitelisted to do this.

Set Up to Authenticate With Your Project's Credentials

This Android app uses JSON credential file locally stored in the resources. You should not do this in your production app. Instead, you should set up your own backend server that authenticates app users. The server should delegate API calls from your client app. This way, you can enforce usage quota per user. Alternatively, you should get the access token on the server side, and supply client app with it. The access token will expire in a short while.

In this sample, we just put the Service Account in the client for ease of use. The app still gets an access token using the service account credential, and use the token to call the API, so you can see how to do so.

In order to try out this sample, visit the Cloud Console, and navigate to: API Manager > Credentials > Create credentials > Service account key > New service account. Create a new service account, and download the JSON credentials file. Put the file in the app resources as app/src/main/res/raw/credential.json.

Again, you should not do this in your production app.

See the Cloud Platform Auth Guide for more information.

Build signed release

This step is optional.

This sample uses ProGuard to decrease the number of methods generated by the gRPC library. It is enabled by default for release build. If you want to build it, change the path, alias and passwords of the keystore file specified in gradle.properties.

importing module "opuslib"

if you bring that into the project , change build.gradle.android property as below:

compileSdkVersion 25
buildToolsVersion "25.0.2"
resourcePrefix "ly__"

defaultConfig {
    minSdkVersion 16
    targetSdkVersion 25
    versionCode 1
    versionName "1.0"
}
sourceSets.main {
    jni.srcDirs = []                // This prevents the auto generation of Android.mk
    jniLibs.srcDir 'src/main/libs'  // This is not necessary unless you have precompiled libraries in your project.
}

task ndkBuild(type: Exec) {
    def ndkDir = android.ndkDirectory
    if (Os.isFamily(Os.FAMILY_WINDOWS)) {
        commandLine 'ndk-build.cmd', '-C', file('src/main/jni').absolutePath
    } else {
        commandLine "$ndkDir/ndk-build", '-C', file('src/main/jni').absolutePath
    }
}

tasks.withType(JavaCompile) {
    compileTask -> compileTask.dependsOn ndkBuild
}

task cleanNative(type: Exec, description: 'Clean JNI object files') {
    def ndkDir = android.ndkDirectory
    commandLine "$ndkDir/ndk-build",
            '-C', file('src/main/jni').absolutePath, // Change src/main/jni the relative path to your jni source
            'clean'
}

clean.dependsOn 'cleanNative'

buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
    debug {
        debuggable true
    }
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published