gpt4 book ai didi

java - GOOGLE_APPLICATION_CREDENTIALS 身份验证无法在远程 ubuntu 机器上运行

转载 作者:行者123 更新时间:2023-12-04 19:25:26 24 4
gpt4 key购买 nike

当我在本地机器(Windows)上运行文档示例时,我设置了指向 json 文件的环境变量并且它可以工作。如果路径不正确,它会警告我也找不到该文件。

// Imports the Google Cloud client library
import com.google.cloud.texttospeech.v1.AudioConfig;
import com.google.cloud.texttospeech.v1.AudioEncoding;
import com.google.cloud.texttospeech.v1.SsmlVoiceGender;
import com.google.cloud.texttospeech.v1.SynthesisInput;
import com.google.cloud.texttospeech.v1.SynthesizeSpeechResponse;
import com.google.cloud.texttospeech.v1.TextToSpeechClient;
import com.google.cloud.texttospeech.v1.VoiceSelectionParams;
import com.google.protobuf.ByteString;
import java.io.FileOutputStream;
import java.io.OutputStream;

/**
* Google Cloud TextToSpeech API sample application. Example usage: mvn package exec:java
* -Dexec.mainClass='com.example.texttospeech.QuickstartSample'
*/
public class QuickstartSample {

/** Demonstrates using the Text-to-Speech API. */
public static void main(String... args) throws Exception {
// Instantiates a client
try (TextToSpeechClient textToSpeechClient = TextToSpeechClient.create()) {
// Set the text input to be synthesized
SynthesisInput input = SynthesisInput.newBuilder().setText("Hello, World!").build();

// Build the voice request, select the language code ("en-US") and the ssml voice gender
// ("neutral")
VoiceSelectionParams voice =
VoiceSelectionParams.newBuilder()
.setLanguageCode("en-US")
.setSsmlGender(SsmlVoiceGender.NEUTRAL)
.build();

// Select the type of audio file you want returned
AudioConfig audioConfig =
AudioConfig.newBuilder().setAudioEncoding(AudioEncoding.MP3).build();

// Perform the text-to-speech request on the text input with the selected voice parameters and
// audio file type
SynthesizeSpeechResponse response =
textToSpeechClient.synthesizeSpeech(input, voice, audioConfig);

// Get the audio contents from the response
ByteString audioContents = response.getAudioContent();

// Write the response to the output file.
try (OutputStream out = new FileOutputStream("output.mp3")) {
out.write(audioContents.toByteArray());
System.out.println("Audio content written to file \"output.mp3\"");
}
}
}
}
https://cloud.google.com/text-to-speech/docs/libraries#windows
当我在远程机器(Ubuntu)上运行相同的 jar 并设置环境变量时。无论如何它都会抛出这个错误。即使我故意设置了错误的位置。
我错过了什么?我在哪里可以看?

Caused by: java.io.IOException: The Application Default Credentialsare not available. They are available if running in Google ComputeEngine. Otherwise, the environment variableGOOGLE_APPLICATION_CREDENTIALS must be defined pointing to a filedefining the credentials. Seehttps://developers.google.com/accounts/docs/application-default-credentialsfor more information.

最佳答案

我犯的错误是输入了两个命令。

GOOGLE_APPLICATION_CREDENTIALS=/path/file.json
java -jar project.jar
代替
GOOGLE_APPLICATION_CREDENTIALS=/path/file.json java -jar project.jar

关于java - GOOGLE_APPLICATION_CREDENTIALS 身份验证无法在远程 ubuntu 机器上运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71606588/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com