Google Cloud Speech API 增强模式错误

Google Cloud Speech API enhance mode error

我正在尝试使用语音 API 中的 setUseEnhanced 字段,但出现如下错误:

java.util.concurrent.ExecutionException: com.google.api.gax.rpc.InvalidArgumentException: io.grpc.StatusRuntimeException: INVALID_ARGUMENT: Invalid recognition 'config': Not qualified to request enhanced model. Requires opt-in for logging.

这是代码

            // Instantiates a SpeechClient
            speech = SpeechClient.create(speechSettings);

            GoogleDataCollectionConfig googleDataCollectionConfig = GoogleDataCollectionConfig.newBuilder()
                    .setLoggingConsentState(LoggingConsentState.ENABLED).build();

            RecognitionMetadata recognitionMetadata = RecognitionMetadata.newBuilder()
                .setRecordingDeviceType(RecordingDeviceType.SMARTPHONE)
                .setInteractionType(InteractionType.PHONE_CALL)
                .build();

            // Builds the sync recognize request
            final RecognitionConfig config = RecognitionConfig.newBuilder()
                .setEncoding(AudioEncoding.FLAC)
                .setLanguageCode(audioLanguageCode)
                .setMaxAlternatives(1)
                .setModel("phone_call")
                .setGoogleDataCollectionOptIn(googleDataCollectionConfig)
                .setUseEnhanced(true)
                .setMetadata(recognitionMetadata)                   
                .build();

根据 Google 文档:

You must opt-in to the audio logging using the instructions in the data logging documentation. If you set useEnhanced to true and you have not enabled audio logging, then you will receive an error.

https://cloud.google.com/speech/data-sharing 的 link 似乎也坏了。

如您所说,link 已损坏,但是,如果您在 Google 中查找 data logging,您可以找到 how to enroll in data logging

这将解决您代码中的异常。