У меня есть проблемы с речью в текст v2 версии vangelid_argument: неверное значение поля ресурса в запросеJAVA

Программисты JAVA общаются здесь
Ответить Пред. темаСлед. тема
Anonymous
 У меня есть проблемы с речью в текст v2 версии vangelid_argument: неверное значение поля ресурса в запросе

Сообщение Anonymous »

У меня есть проблема, когда я пытаюсь запустить приложение, используя речь в текст v2. Я хочу преобразовать речь в текст, используя микрофон. Я использую переменную google_application_credentials и используя v1 все работает для меня. Однако, когда я мигрировал на V2, я получаю следующее исключение < /p>
com.google.api.gax.rpc.invalidargumentException: io.grpc.statusruntimeexcept .
at com.google.api.gax.rpc.apiexceptionFactory.CreateException (apiexceptionFactory.java:92)
at com.google.api.gax.grpc.grpcapiexceptionfactory.create (grpcapiexceptactory.java:98 )
at com.google.api.gax.grpc.grpcapiexceptionfactory.create (grpcapiexceptionfactory.java:66)
at com.google.api.gax.grpc.exceptionresponseobserver.onerrorimpl (ExceptionResponseobserver. )
at com.google.api.gax.rpc.statecheckingResponseObserver.onerror (stateCheckingResponseObserver.java:84)
at com.google.api.gax.grpc.grpcdirectreamcontroler $ recpionobserAdapter.oncleserectreamcontreamcontremcroller $ recpionbserveradapter.oncleserectreamcontreamcontreamcroler : 148)
at io.grpc.partialForwardingCallCallListener.onClose (PartialForwardingCallCallListener.java:39)
at io.grpc.forwardingcallcalllisterener.onclose (forwardingclientCallListener.java:23)
at io.grpc. ForcuryClientCallListener $ simpleArdingClientCallListener.onClose (forgningClientCallListener.java:40)
at com.google.api.gax.grpc.channelpool $ releasingcallcall $ 1.onclose (Channelpool.java:569)
at io.grp. .DelayedClientCall $ DoyedEdListener $ 3.RUN (DoledEdClientCall.java:489)
at io.grpc.internal.delayedcallcall $ dolededListener.delayorexecut DoyededListener.onClose (DoledEdClientCall.java:486)
at io.grpc.internal.clientcallimpl.closeobserver (clientCallimpl.java:564)
at io.grpc.internal.clientcallimpl.ccess $ 100 (wulfitcallimpl.java. : 72)
at io.grpc.internal.clientCallimpl $ clientStreamListenerimpl $ 1StreamClosed.Runinternal (clientCallimpl.java:729)
at io.grpc.internal.clientcallimpl $ clientStreamEnerImpl $ 1StreamClemplose.RunincText. : 710)
at io.grpc.internal.contextrunnable.run (contextrunnable.java:37)
at io.grpc.internal.serializeexecutor.run (serializeexecutor.java:133)
java.base /java.util.concurrent.threadpoolexecutor.runworker (threadpoolexecutor.java:1128)
at java.base /java.util.concurrent.threadpoolexecutor $ keorker.run (Threatpoolexecutor.java:628)
at java.base /java.lang.thread.run (thread.java:834)
вызван: io.grpc.statusruntimeexception: Invalid_argument: Неверное значение поля ресурса в запросе.
at io. grpc.status.asruntimeexception (status.java:532)
... 17 еще < /p>
my code: < /p>

package com.mycompany.testgoogleversio2;

import com.google.api.gax.rpc.ClientStream;
import com.google.api.gax.rpc.ResponseObserver;
import com.google.api.gax.rpc.StreamController;
import com.google.cloud.speech.v2.ExplicitDecodingConfig;
import com.google.cloud.speech.v2.RecognitionConfig;
import com.google.cloud.speech.v2.SpeechClient;
import com.google.cloud.speech.v2.SpeechRecognitionAlternative;
import com.google.cloud.speech.v2.StreamingRecognitionConfig;
import com.google.cloud.speech.v2.StreamingRecognitionResult;
import com.google.cloud.speech.v2.StreamingRecognizeRequest;
import com.google.cloud.speech.v2.StreamingRecognizeResponse;

import com.google.protobuf.ByteString;
import java.util.ArrayList;
import java.util.List;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.TargetDataLine;

/
public class TestGoogleMicrofone {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
ResponseObserver responseObserver = null;
try (SpeechClient client = SpeechClient.create()) {

responseObserver
= new ResponseObserver() {
ArrayList responses = new ArrayList();

public void onStart(StreamController controller) {
System.out.println("Startuje");
}

public void onResponse(StreamingRecognizeResponse response) {
System.out.println("laduje");
StreamingRecognitionResult result = response.getResultsList().get(0);
SpeechRecognitionAlternative alternative = result.getAlternativesList().get(0);
System.out.printf("Transcript : %s\n", alternative.getTranscript() + ", is final: " + result.getIsFinal());
responses.add(response);
}

public void onComplete() {
for (StreamingRecognizeResponse response : responses) {
StreamingRecognitionResult result = response.getResultsList().get(0);
SpeechRecognitionAlternative alternative = result.getAlternativesList().get(0);
System.out.printf("Transcript : %s\n", alternative.getTranscript());
}
}

public void onError(Throwable t) {
t.printStackTrace();
}

};

ClientStream clientStream
= client.streamingRecognizeCallable().splitCall(responseObserver);

List allLanguageCodes = new ArrayList();
allLanguageCodes.add("pl-PL");
RecognitionConfig recognitionConfig
= RecognitionConfig.newBuilder().setExplicitDecodingConfig(
ExplicitDecodingConfig.newBuilder()
.setEncoding(ExplicitDecodingConfig.AudioEncoding.LINEAR16)
.setSampleRateHertz(16000)
.setAudioChannelCount(1)
).addLanguageCodes("en-US").setModel("chirp").build();

//.setLanguageCode("en-US")
StreamingRecognitionConfig streamingRecognitionConfig
= StreamingRecognitionConfig.newBuilder().setConfig(recognitionConfig).setConfig(recognitionConfig).build();

StreamingRecognizeRequest request
= StreamingRecognizeRequest.newBuilder()
.setStreamingConfig(streamingRecognitionConfig)
.build(); // The first request in a streaming call has to be a config

AudioFormat format = new AudioFormat(16000.0f, 16, 1, true, false);
TargetDataLine microphone;
microphone = AudioSystem.getTargetDataLine(format);

DataLine.Info info = new DataLine.Info(TargetDataLine.class, format);
microphone = (TargetDataLine) AudioSystem.getLine(info);
microphone.open(format);

//ByteArrayOutputStream out = new ByteArrayOutputStream();
int numBytesRead;
int CHUNK_SIZE = 3200;
byte[] data = new byte[microphone.getBufferSize() / 5];
//byte[] data = new byte[CHUNK_SIZE];
microphone.start();

clientStream.send(request);
// SampleRate:16000Hz, SampleSizeInBits: 16, Number of channels: 1, Signed: true,
// bigEndian: false

long startTime = System.currentTimeMillis();
int bytesRead = 0;
try {
System.out.println("Start speaking");
while (true) {
System.out.println("Jestem2");
long estimatedTime = System.currentTimeMillis() - startTime;
numBytesRead = microphone.read(data, 0, microphone.getBufferSize() / 5);
bytesRead += numBytesRead;
if (estimatedTime > 60000) { // 60 seconds
System.out.println("Stop speakingaaa.");
microphone.close();
//clientStream.closeSend();
break;
}

request
= StreamingRecognizeRequest.newBuilder().setStreamingConfig(streamingRecognitionConfig)
.setAudio(ByteString.copyFrom(data))
.build();
System.out.println(request.getRecognizer());

clientStream.send(request);
//Thread.sleep(100);
}
} catch (Exception e) {
e.printStackTrace();
}
} catch (Exception e) {
e.printStackTrace();
}
responseObserver.onComplete();
}

}
< /code>
Я понятия не имею, что я делаю не так>

Подробнее здесь: https://stackoverflow.com/questions/794 ... d-resource
Реклама
Ответить Пред. темаСлед. тема

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

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

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

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

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

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