1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License 15 */ 16 package com.android.voicemail.impl.transcribe.grpc; 17 18 import android.support.annotation.WorkerThread; 19 import com.google.internal.communications.voicemailtranscription.v1.GetTranscriptRequest; 20 import com.google.internal.communications.voicemailtranscription.v1.SendTranscriptionFeedbackRequest; 21 import com.google.internal.communications.voicemailtranscription.v1.TranscribeVoicemailAsyncRequest; 22 import com.google.internal.communications.voicemailtranscription.v1.TranscribeVoicemailRequest; 23 import com.google.internal.communications.voicemailtranscription.v1.VoicemailTranscriptionServiceGrpc; 24 import io.grpc.StatusRuntimeException; 25 26 /** Wrapper around Grpc transcription server stub */ 27 public class TranscriptionClient { 28 29 private final VoicemailTranscriptionServiceGrpc.VoicemailTranscriptionServiceBlockingStub stub; 30 TranscriptionClient( VoicemailTranscriptionServiceGrpc.VoicemailTranscriptionServiceBlockingStub stub)31 TranscriptionClient( 32 VoicemailTranscriptionServiceGrpc.VoicemailTranscriptionServiceBlockingStub stub) { 33 this.stub = stub; 34 } 35 36 @WorkerThread sendSyncRequest(TranscribeVoicemailRequest request)37 public TranscriptionResponseSync sendSyncRequest(TranscribeVoicemailRequest request) { 38 try { 39 return new TranscriptionResponseSync(stub.transcribeVoicemail(request)); 40 } catch (StatusRuntimeException e) { 41 return new TranscriptionResponseSync(e.getStatus()); 42 } 43 } 44 45 @WorkerThread sendUploadRequest(TranscribeVoicemailAsyncRequest request)46 public TranscriptionResponseAsync sendUploadRequest(TranscribeVoicemailAsyncRequest request) { 47 try { 48 return new TranscriptionResponseAsync(stub.transcribeVoicemailAsync(request)); 49 } catch (StatusRuntimeException e) { 50 return new TranscriptionResponseAsync(e.getStatus()); 51 } 52 } 53 54 @WorkerThread sendGetTranscriptRequest(GetTranscriptRequest request)55 public GetTranscriptResponseAsync sendGetTranscriptRequest(GetTranscriptRequest request) { 56 try { 57 return new GetTranscriptResponseAsync(stub.getTranscript(request)); 58 } catch (StatusRuntimeException e) { 59 return new GetTranscriptResponseAsync(e.getStatus()); 60 } 61 } 62 63 @WorkerThread sendTranscriptFeedbackRequest( SendTranscriptionFeedbackRequest request)64 public TranscriptionFeedbackResponseAsync sendTranscriptFeedbackRequest( 65 SendTranscriptionFeedbackRequest request) { 66 try { 67 return new TranscriptionFeedbackResponseAsync(stub.sendTranscriptionFeedback(request)); 68 } catch (StatusRuntimeException e) { 69 return new TranscriptionFeedbackResponseAsync(e.getStatus()); 70 } 71 } 72 } 73