Как указать выходной формат в речевом тексту v2 распознавать запросы?JAVA

Программисты JAVA общаются здесь
Ответить
Anonymous
 Как указать выходной формат в речевом тексту v2 распознавать запросы?

Сообщение Anonymous »

Я пытаюсь использовать v2 речи в текстовый API и не могу выяснить, как пропустить установку outputformatconfig для установки или НДС в качестве выходного формата для транскрипции.
класс Java для uncomectionOutputConfig не имеет выходного формата. />https://cloud.google.com/speech-to-text ... tputConfig
https://cloud.google.com/speech-to-text ... h.v2public final class RecognitionOutputConfig extends GeneratedMessageV3 implements RecognitionOutputConfigOrBuilder {
private static final long serialVersionUID = 0L;
private int outputCase_;
private Object output_;
public static final int GCS_OUTPUT_CONFIG_FIELD_NUMBER = 1;
public static final int INLINE_RESPONSE_CONFIG_FIELD_NUMBER = 2;
private byte memoizedIsInitialized;
private static final RecognitionOutputConfig DEFAULT_INSTANCE = new RecognitionOutputConfig();
< /code>
Я пытался искать каждый и просмотреть разные классы, чтобы увидеть, у кого есть это свойство, и я рисую пробелы. Любая помощь будет очень оценена. Нам нужна расширяемость для поддержки как форматов SRT, так и VTT. < /P>
// Imports the Google Cloud client library
import com.google.api.gax.longrunning.OperationFuture;
import com.google.cloud.speech.v2.AutoDetectDecodingConfig;
import com.google.cloud.speech.v2.CreateRecognizerRequest;
import com.google.cloud.speech.v2.OperationMetadata;
import com.google.cloud.speech.v2.RecognitionConfig;
import com.google.cloud.speech.v2.RecognizeRequest;
import com.google.cloud.speech.v2.RecognizeResponse;
import com.google.cloud.speech.v2.Recognizer;
import com.google.cloud.speech.v2.SpeechClient;
import com.google.cloud.speech.v2.SpeechRecognitionAlternative;
import com.google.cloud.speech.v2.SpeechRecognitionResult;
import com.google.protobuf.ByteString;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import java.util.concurrent.ExecutionException;

public class QuickstartSampleV2 {

public static void main(String[] args) throws IOException, ExecutionException,
InterruptedException {
String projectId = "my-project-id";
String filePath = "path/to/audioFile.raw";
String recognizerId = "my-recognizer-id";
quickstartSampleV2(projectId, filePath, recognizerId);
}

public static void quickstartSampleV2(String projectId, String filePath, String recognizerId)
throws IOException, ExecutionException, InterruptedException {

// Initialize client that will be used to send requests. This client only needs to be created
// once, and can be reused for multiple requests. After completing all of your requests, call
// the "close" method on the client to safely clean up any remaining background resources.
try (SpeechClient speechClient = SpeechClient.create()) {
Path path = Paths.get(filePath);
byte[] data = Files.readAllBytes(path);
ByteString audioBytes = ByteString.copyFrom(data);

String parent = String.format("projects/%s/locations/global", projectId);

// First, create a recognizer
Recognizer recognizer = Recognizer.newBuilder()
.setModel("latest_long")
.addLanguageCodes("en-US")
.build();

CreateRecognizerRequest createRecognizerRequest = CreateRecognizerRequest.newBuilder()
.setParent(parent)
.setRecognizerId(recognizerId)
.setRecognizer(recognizer)
.build();

OperationFuture operationFuture =
speechClient.createRecognizerAsync(createRecognizerRequest);
recognizer = operationFuture.get();

// Next, create the transcription request
RecognitionConfig recognitionConfig = RecognitionConfig.newBuilder()
.setAutoDecodingConfig(AutoDetectDecodingConfig.newBuilder().build())
.build();
RecognitionOutputConfig.Builder outputConfigBuilder = RecognitionOutputConfig.newBuilder()
.setGcsOutputConfig(GcsOutputConfig.newBuilder()
.setUri("gs://" + bucketName + "/output/" + file.getFileName().toString() + "."+subtitleFormat))
.setOutputFormatConfig(OutputFormatConfig.newBuilder().build);

RecognizeRequest request = RecognizeRequest.newBuilder()
.setConfig(recognitionConfig)
.setRecognizer(recognizer.getName())
.setRecognitionOutputConfig(outputConfigBuilder.build())
.setContent(audioBytes)
.build();

RecognizeResponse response = speechClient.recognize(request);
List 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.
if (result.getAlternativesCount() > 0) {
SpeechRecognitionAlternative alternative = result.getAlternativesList().get(0);
System.out.printf("Transcription: %s%n", alternative.getTranscript());
}
}
}
}
}


Подробнее здесь: https://stackoverflow.com/questions/795 ... e-requests
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «JAVA»