Android的Google Speech-to-Text API使用RPC beta自动检测语言

问题描述 投票:1回答:1

我正在尝试为Android实现应用程序,该应用程序将使用具有语言自动检测功能的Google Cloud Speech To Text API。在official documentation中,我找到了示例project for android。但是问题在于它使用google.cloud.speech.v1.Speech,而multiple languages supported仅在beta版本中google.cloud.speech.v1p1beta1.Speech

要指定替代语言,需要设置仅在alternativeLanguageCodes中声明的字段beta version,而我不知道如何更改项目以使用beta。

我试图更新gradle依赖关系,并导入新的程序包,但是不起作用。

项目的分级摘要

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
        maven { url 'https://maven.google.com' }
        google()

        maven {
            url "https://plugins.gradle.org/m2/"
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.4.0'
        classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.8'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
        maven { url 'https://maven.google.com' }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

应用程式的分级脚本

apply plugin: 'com.android.application'
apply plugin: 'com.google.protobuf'

ext {
    supportLibraryVersion = '28.0.0'
    grpcVersion = '1.20.0'
}

android {
    compileSdkVersion 28
    buildToolsVersion '28.0.3'

    defaultConfig {
        applicationId ""
        targetSdkVersion 28
        versionCode 1
        versionName '1.0'

        minSdkVersion 16
    }

    signingConfigs {
        release {
            storeFile file(project.properties.storeFile)
            storePassword project.properties.storePassword
            keyAlias project.properties.keyAlias
            keyPassword project.properties.keyPassword
        }
    }

    flavorDimensions "default"
    productFlavors {
        dev {
            dimension "default"
            // Minimum version with platform multi-dex support
            minSdkVersion 16
        }
        prod {
            dimension "default"
            // Minimum version that can run gRPC (TLS extension)
            minSdkVersion 16
        }
    }

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

    configurations.all {
        resolutionStrategy.force 'com.google.code.findbugs:jsr305:3.0.2'
        resolutionStrategy.force "com.android.support:support-annotations:$supportLibraryVersion"
    }
}

protobuf {
    protoc {
        artifact = 'com.google.protobuf:protoc:3.3.0'
    }
    plugins {
        javalite {
            artifact = "com.google.protobuf:protoc-gen-javalite:3.0.0"
        }
        grpc {
            artifact = "io.grpc:protoc-gen-grpc-java:${grpcVersion}"
        }
    }
    generateProtoTasks {
        all().each { task ->
            task.plugins {
                javalite {}
                grpc {
                    // Options added to --grpc_out
                    option 'lite'
                }
            }
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])

    // Support libraries
    compile "com.android.support:design:$supportLibraryVersion"
    compile "com.android.support:cardview-v7:$supportLibraryVersion"
    compile "com.android.support:recyclerview-v7:$supportLibraryVersion"

    // gRPC
    compile "io.grpc:grpc-okhttp:$grpcVersion"
    compile "io.grpc:grpc-protobuf-lite:$grpcVersion"
    compile "io.grpc:grpc-stub:$grpcVersion"
    compile 'javax.annotation:javax.annotation-api:1.2'
    protobuf 'com.google.protobuf:protobuf-java:3.5.1'

    // OAuth2 for Google API
    compile('com.google.auth:google-auth-library-oauth2-http:0.7.0') {
        exclude module: 'httpclient'
    }

    // Tests
    testCompile 'junit:junit:4.12'
    androidTestCompile 'com.android.support.test:runner:1.0.2'
    androidTestCompile 'com.android.support.test.espresso:espresso-core:3.0.2'
}

task copySecretKey(type: Copy) {
    File secretKey = file "$System.env.GOOGLE_APPLICATION_CREDENTIALS"
    from secretKey.getParent()
    include secretKey.getName()
    into 'src/main/res/raw'
    rename secretKey.getName(), "credential.json"
}
preBuild.dependsOn(copySecretKey)

尝试导入测试版程序包,但未解决:

import com.google.cloud.speech.v1p1beta1.RecognitionAudio;
import com.google.cloud.speech.v1p1beta1.RecognitionConfig;
import com.google.cloud.speech.v1p1beta1.RecognizeRequest;
import com.google.cloud.speech.v1p1beta1.RecognizeResponse;
import com.google.cloud.speech.v1p1beta1.SpeechGrpc;
import com.google.cloud.speech.v1p1beta1.SpeechRecognitionAlternative;
import com.google.cloud.speech.v1p1beta1.SpeechRecognitionResult;
import com.google.cloud.speech.v1p1beta1.StreamingRecognitionConfig;
import com.google.cloud.speech.v1p1beta1.StreamingRecognitionResult;
import com.google.cloud.speech.v1p1beta1.StreamingRecognizeRequest;
import com.google.cloud.speech.v1p1beta1.StreamingRecognizeResponse;
android google-cloud-platform speech-recognition speech-to-text google-cloud-speech
1个回答
0
投票

我也在寻找相同的东西。您对此问题有解决方案吗?

© www.soinside.com 2019 - 2024. All rights reserved.