Java SpeechClient未在intellij中导入
我正在尝试这个: 但是导入Java SpeechClient未在intellij中导入,java,google-cloud-platform,Java,Google Cloud Platform,我正在尝试这个: 但是导入import com.google.cloud.SpeechClient.v1.SpeechClient显示错误。云语音api下的其他类可以很好地导入 我已经为我的项目创建了GCP服务帐户并下载了json文件,我甚至使用powershell将我的google凭据设置为该json文件 // Imports the Google Cloud client library import com.google.cloud.speech.v1.RecognitionAudio;
import com.google.cloud.SpeechClient.v1.SpeechClient代码>显示错误。云语音api下的其他类可以很好地导入
我已经为我的项目创建了GCP服务帐户并下载了json文件,我甚至使用powershell将我的google凭据设置为该json文件
// Imports the Google Cloud client library
import com.google.cloud.speech.v1.RecognitionAudio;
import com.google.cloud.speech.v1.RecognitionConfig;
import com.google.cloud.speech.v1.RecognitionConfig.AudioEncoding;
import com.google.cloud.speech.v1.RecognizeResponse;
import com.google.cloud.speech.v1.SpeechClient;
import com.google.cloud.speech.v1.SpeechRecognitionAlternative;
import com.google.cloud.speech.v1.SpeechRecognitionResult;
import com.google.protobuf.ByteString;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
public class QuickstartSample {
/**
* Demonstrates using the Speech API to transcribe an audio file.
*/
public static void main(String... args) throws Exception {
// Instantiates a client
try (SpeechClient speechClient = SpeechClient.create()) {
// The path to the audio file to transcribe
String fileName = "./resources/audio.raw";
// Reads the audio file into memory
Path path = Paths.get(fileName);
byte[] data = Files.readAllBytes(path);
ByteString audioBytes = ByteString.copyFrom(data);
// Builds the sync recognize request
RecognitionConfig config = RecognitionConfig.newBuilder()
.setEncoding(AudioEncoding.LINEAR16)
.setSampleRateHertz(16000)
.setLanguageCode("en-US")
.build();
RecognitionAudio audio = RecognitionAudio.newBuilder()
.setContent(audioBytes)
.build();
// Performs speech recognition on the audio file
RecognizeResponse response = speechClient.recognize(config, audio);
List<SpeechRecognitionResult> results = response.getResultsList();
for (SpeechRecognitionResult result : results) {
// There can be several alternative transcripts for a given chunk of speech. Just use the
// first (most likely) one here.
SpeechRecognitionAlternative alternative = result.getAlternativesList().get(0);
System.out.printf("Transcription: %s%n", alternative.getTranscript());
}
}
}
}
//导入Google云客户端库
导入com.google.cloud.speech.v1.RecognitionAudio;
导入com.google.cloud.speech.v1.RecognitionConfig;
导入com.google.cloud.speech.v1.RecognitionConfig.AudioEncoding;
导入com.google.cloud.speech.v1.recognizerResponse;
导入com.google.cloud.SpeechClient.v1.SpeechClient;
导入com.google.cloud.speech.v1.speechrecognitionalAlternative;
导入com.google.cloud.speech.v1.SpeechRecognitionResult;
导入com.google.protobuf.ByteString;
导入java.nio.file.Files;
导入java.nio.file.Path;
导入java.nio.file.path;
导入java.util.List;
公共类快速入门示例{
/**
*演示如何使用语音API转录音频文件。
*/
公共静态void main(字符串…参数)引发异常{
//实例化客户机
try(SpeechClient SpeechClient=SpeechClient.create()){
//要转录的音频文件的路径
字符串fileName=“./resources/audio.raw”;
//将音频文件读入内存
Path Path=Path.get(文件名);
字节[]数据=文件。readAllBytes(路径);
ByteString audioBytes=ByteString.copyFrom(数据);
//生成同步识别请求
RecognitionConfig=RecognitionConfig.newBuilder()
.setEncoding(AudioEncoding.LINEAR16)
.setSampleRateHertz(16000)
.setLanguageCode(“en-US”)
.build();
RecognitionAudio=RecognitionAudio.newBuilder()
.setContent(音频字节)
.build();
//对音频文件执行语音识别
RecognizeResponse response=speechClient.recognize(配置,音频);
列表结果=response.getResultsList();
for(SpeechRecognitionResult:results){
//对于给定的一段演讲,可以有多个备选文本。只需使用
//第一个(很可能)在这里。
speechrecognitionalAlternative=result.getAlternativesList().get(0);
System.out.printf(“转录:%s%n”,alternative.getTranscript());
}
}
}
}
它到底显示了什么错误?基本上是说找不到特定的类。最好复制并粘贴准确的错误消息。