diff options
author | Treehugger Robot <treehugger-gerrit@google.com> | 2017-11-29 17:32:50 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2017-11-29 17:32:50 +0000 |
commit | 9c93611edcb369f4e4ac7cff5c261bd1da65c347 (patch) | |
tree | c59375133ee2f7236c17758706e88a492db81259 /java/com/android/voicemail/impl/transcribe/TranscriptionUtils.java | |
parent | 5b6d823a45fe56cf9c36e5b00908831049c1d827 (diff) | |
parent | 70fedf8d6caee1177ee891bbfff404dc48867c16 (diff) |
Merge "Adding transcription rating feedback"
Diffstat (limited to 'java/com/android/voicemail/impl/transcribe/TranscriptionUtils.java')
-rw-r--r-- | java/com/android/voicemail/impl/transcribe/TranscriptionUtils.java | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/java/com/android/voicemail/impl/transcribe/TranscriptionUtils.java b/java/com/android/voicemail/impl/transcribe/TranscriptionUtils.java index a001f179a..36b1400be 100644 --- a/java/com/android/voicemail/impl/transcribe/TranscriptionUtils.java +++ b/java/com/android/voicemail/impl/transcribe/TranscriptionUtils.java @@ -16,17 +16,38 @@ package com.android.voicemail.impl.transcribe; import android.annotation.TargetApi; -import android.os.Build.VERSION_CODES; +import android.content.Context; +import android.net.Uri; import android.util.Base64; import com.android.dialer.common.Assert; +import com.google.internal.communications.voicemailtranscription.v1.AudioFormat; import com.google.protobuf.ByteString; +import java.io.IOException; +import java.io.InputStream; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; /** Utility methods used by this transcription package. */ public class TranscriptionUtils { + static final String AMR_PREFIX = "#!AMR\n"; - @TargetApi(VERSION_CODES.O) + // Uses try-with-resource + @TargetApi(android.os.Build.VERSION_CODES.M) + static ByteString getAudioData(Context context, Uri voicemailUri) { + try (InputStream in = context.getContentResolver().openInputStream(voicemailUri)) { + return ByteString.readFrom(in); + } catch (IOException e) { + return null; + } + } + + static AudioFormat getAudioFormat(ByteString audioData) { + return audioData != null && audioData.startsWith(ByteString.copyFromUtf8(AMR_PREFIX)) + ? AudioFormat.AMR_NB_8KHZ + : AudioFormat.AUDIO_FORMAT_UNSPECIFIED; + } + + @TargetApi(android.os.Build.VERSION_CODES.O) static String getFingerprintFor(ByteString data) { Assert.checkArgument(data != null); try { |