Przemyslaw Szczepaniak | 90d15d2 | 2013-06-14 12:02:53 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not |
| 5 | * use this file except in compliance with the License. You may obtain a copy of |
| 6 | * 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, WITHOUT |
| 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 | * License for the specific language governing permissions and limitations under |
| 14 | * the License. |
| 15 | */ |
| 16 | package android.speech.tts; |
| 17 | |
| 18 | |
| 19 | |
| 20 | /** |
| 21 | * Writes data about a given speech synthesis request for V2 API to the event logs. |
| 22 | * The data that is logged includes the calling app, length of the utterance, |
| 23 | * synthesis request configuration and the latency and overall time taken. |
| 24 | */ |
| 25 | class EventLoggerV2 extends AbstractEventLogger { |
| 26 | private final SynthesisRequestV2 mRequest; |
| 27 | |
| 28 | EventLoggerV2(SynthesisRequestV2 request, int callerUid, int callerPid, String serviceApp) { |
| 29 | super(callerUid, callerPid, serviceApp); |
| 30 | mRequest = request; |
| 31 | } |
| 32 | |
| 33 | @Override |
| 34 | protected void logFailure(int statusCode) { |
| 35 | // We don't report stopped syntheses because their overall |
| 36 | // total time spent will be inaccurate (will not correlate with |
| 37 | // the length of the utterance). |
| 38 | if (statusCode != TextToSpeechClient.Status.STOPPED) { |
| 39 | EventLogTags.writeTtsV2SpeakFailure(mServiceApp, |
| 40 | mCallerUid, mCallerPid, getUtteranceLength(), getRequestConfigString(), statusCode); |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | @Override |
| 45 | protected void logSuccess(long audioLatency, long engineLatency, long engineTotal) { |
| 46 | EventLogTags.writeTtsV2SpeakSuccess(mServiceApp, |
| 47 | mCallerUid, mCallerPid, getUtteranceLength(), getRequestConfigString(), |
| 48 | engineLatency, engineTotal, audioLatency); |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * @return the length of the utterance for the given synthesis, 0 |
| 53 | * if the utterance was {@code null}. |
| 54 | */ |
| 55 | private int getUtteranceLength() { |
| 56 | final String utterance = mRequest.getText(); |
| 57 | return utterance == null ? 0 : utterance.length(); |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Returns a string representation of the synthesis request configuration. |
| 62 | */ |
| 63 | private String getRequestConfigString() { |
| 64 | // Ensure the bundles are unparceled. |
| 65 | mRequest.getVoiceParams().size(); |
| 66 | mRequest.getAudioParams().size(); |
| 67 | |
Przemyslaw Szczepaniak | 97cd647 | 2013-10-25 12:04:47 +0100 | [diff] [blame] | 68 | return new StringBuilder(64).append("VoiceName: ").append(mRequest.getVoiceName()) |
Przemyslaw Szczepaniak | 90d15d2 | 2013-06-14 12:02:53 +0100 | [diff] [blame] | 69 | .append(" ,VoiceParams: ").append(mRequest.getVoiceParams()) |
| 70 | .append(" ,SystemParams: ").append(mRequest.getAudioParams()) |
| 71 | .append("]").toString(); |
| 72 | } |
| 73 | } |