diff options
author | mdooley <mdooley@google.com> | 2017-11-03 16:08:08 -0700 |
---|---|---|
committer | zachh <zachh@google.com> | 2017-11-11 06:38:57 +0000 |
commit | 1a56facd7bf477e6fb8f0ec1093696ba83e4fd74 (patch) | |
tree | 2ad1b087d306a9f6f63d6b1872bd782fc98f796f /java/com/android/voicemail/impl/transcribe | |
parent | 6af2e14a28e27a38525a08c920e7453c2448689a (diff) |
Allow the client to specify voicemail transcript id's
This is needed for rating transcription quality since we don't
persist the transcript id. The id we generate is just the md5
hash of the voicemail audio data.
Bug: 68712148
Test: manual and updated unit tests
PiperOrigin-RevId: 174527907
Change-Id: I7a29bf5a96447129fc1437074f20ecebcdb1f43b
Diffstat (limited to 'java/com/android/voicemail/impl/transcribe')
3 files changed, 61 insertions, 6 deletions
diff --git a/java/com/android/voicemail/impl/transcribe/TranscriptionConfigProvider.java b/java/com/android/voicemail/impl/transcribe/TranscriptionConfigProvider.java index f4996a097..98c8461f5 100644 --- a/java/com/android/voicemail/impl/transcribe/TranscriptionConfigProvider.java +++ b/java/com/android/voicemail/impl/transcribe/TranscriptionConfigProvider.java @@ -80,6 +80,11 @@ public class TranscriptionConfigProvider { .getBoolean("voicemail_transcription_donation_available", false); } + public boolean useClientGeneratedVoicemailIds() { + return ConfigProviderBindings.get(context) + .getBoolean("voicemail_transcription_client_generated_voicemail_ids", false); + } + @Override public String toString() { return String.format( diff --git a/java/com/android/voicemail/impl/transcribe/TranscriptionTaskAsync.java b/java/com/android/voicemail/impl/transcribe/TranscriptionTaskAsync.java index f946607b5..808bf0f87 100644 --- a/java/com/android/voicemail/impl/transcribe/TranscriptionTaskAsync.java +++ b/java/com/android/voicemail/impl/transcribe/TranscriptionTaskAsync.java @@ -17,6 +17,7 @@ package com.android.voicemail.impl.transcribe; import android.app.job.JobWorkItem; import android.content.Context; +import android.support.annotation.VisibleForTesting; import android.util.Pair; import com.android.dialer.common.Assert; import com.android.dialer.logging.DialerImpression; @@ -121,13 +122,21 @@ public class TranscriptionTaskAsync extends TranscriptionTask { return new Pair<>(null, TranscriptionStatus.FAILED_NO_RETRY); } + @VisibleForTesting TranscribeVoicemailAsyncRequest getUploadRequest() { - return TranscribeVoicemailAsyncRequest.newBuilder() - .setVoicemailData(audioData) - .setAudioFormat(encoding) - .setDonationPreference( - isDonationEnabled() ? DonationPreference.DONATE : DonationPreference.DO_NOT_DONATE) - .build(); + TranscribeVoicemailAsyncRequest.Builder builder = + TranscribeVoicemailAsyncRequest.newBuilder() + .setVoicemailData(audioData) + .setAudioFormat(encoding) + .setDonationPreference( + isDonationEnabled() ? DonationPreference.DONATE : DonationPreference.DO_NOT_DONATE); + // Generate the transcript id locally if configured to do so, or if voicemail donation is + // available (because rating donating voicemails requires locally generated voicemail ids). + if (configProvider.useClientGeneratedVoicemailIds() + || configProvider.isVoicemailDonationAvailable()) { + builder.setTranscriptionId(TranscriptionUtils.getFingerprintFor(audioData)); + } + return builder.build(); } private boolean isDonationEnabled() { diff --git a/java/com/android/voicemail/impl/transcribe/TranscriptionUtils.java b/java/com/android/voicemail/impl/transcribe/TranscriptionUtils.java new file mode 100644 index 000000000..a001f179a --- /dev/null +++ b/java/com/android/voicemail/impl/transcribe/TranscriptionUtils.java @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2017 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ +package com.android.voicemail.impl.transcribe; + +import android.annotation.TargetApi; +import android.os.Build.VERSION_CODES; +import android.util.Base64; +import com.android.dialer.common.Assert; +import com.google.protobuf.ByteString; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; + +/** Utility methods used by this transcription package. */ +public class TranscriptionUtils { + + @TargetApi(VERSION_CODES.O) + static String getFingerprintFor(ByteString data) { + Assert.checkArgument(data != null); + try { + MessageDigest md = MessageDigest.getInstance("MD5"); + byte[] md5Bytes = md.digest(data.toByteArray()); + return Base64.encodeToString(md5Bytes, Base64.DEFAULT); + } catch (NoSuchAlgorithmException e) { + Assert.fail(e.toString()); + } + return null; + } +} |