|
| 1 | +/* |
| 2 | + * Copyright 2018 Google LLC |
| 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 | + * https://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.google.cloud.texttospeech.v1beta1; |
| 17 | + |
| 18 | +import com.google.common.base.Preconditions; |
| 19 | +import java.util.logging.Level; |
| 20 | +import java.util.logging.Logger; |
| 21 | +import org.junit.Test; |
| 22 | + |
| 23 | +@javax.annotation.Generated("by GAPIC") |
| 24 | +public class TextToSpeechSmokeTest { |
| 25 | + private static final String PROJECT_ENV_NAME = "GOOGLE_CLOUD_PROJECT"; |
| 26 | + private static final String LEGACY_PROJECT_ENV_NAME = "GCLOUD_PROJECT"; |
| 27 | + |
| 28 | + @Test |
| 29 | + public void run() { |
| 30 | + main(null); |
| 31 | + } |
| 32 | + |
| 33 | + public static void main(String args[]) { |
| 34 | + Logger.getLogger("").setLevel(Level.WARNING); |
| 35 | + try { |
| 36 | + executeNoCatch(); |
| 37 | + System.out.println("OK"); |
| 38 | + } catch (Exception e) { |
| 39 | + System.err.println("Failed with exception:"); |
| 40 | + e.printStackTrace(System.err); |
| 41 | + System.exit(1); |
| 42 | + } |
| 43 | + } |
| 44 | + |
| 45 | + public static void executeNoCatch() throws Exception { |
| 46 | + try (TextToSpeechClient client = TextToSpeechClient.create()) { |
| 47 | + String text = "test"; |
| 48 | + SynthesisInput input = SynthesisInput.newBuilder().setText(text).build(); |
| 49 | + String languageCode = "en-US"; |
| 50 | + VoiceSelectionParams voice = |
| 51 | + VoiceSelectionParams.newBuilder().setLanguageCode(languageCode).build(); |
| 52 | + AudioEncoding audioEncoding = AudioEncoding.MP3; |
| 53 | + AudioConfig audioConfig = AudioConfig.newBuilder().setAudioEncoding(audioEncoding).build(); |
| 54 | + |
| 55 | + SynthesizeSpeechResponse response = client.synthesizeSpeech(input, voice, audioConfig); |
| 56 | + } |
| 57 | + } |
| 58 | + |
| 59 | + private static String getProjectId() { |
| 60 | + String projectId = System.getProperty(PROJECT_ENV_NAME, System.getenv(PROJECT_ENV_NAME)); |
| 61 | + if (projectId == null) { |
| 62 | + projectId = |
| 63 | + System.getProperty(LEGACY_PROJECT_ENV_NAME, System.getenv(LEGACY_PROJECT_ENV_NAME)); |
| 64 | + } |
| 65 | + Preconditions.checkArgument(projectId != null, "A project ID is required."); |
| 66 | + return projectId; |
| 67 | + } |
| 68 | +} |
0 commit comments