Я пытаюсь отправить аудиофайл в API-интерфейс диалогового окна для обнаружения намерения.У меня уже есть агент, работающий довольно хорошо, но только с текстом.Я пытаюсь добавить функцию аудио, но безуспешно.
Я использую пример (Java), представленный на этой странице:
https://cloud.google.com/dialogflow-enterprise/docs/detect-intent-audio#detect-intent-text-java
Это мой код:
public DetectIntentResponse detectIntentAudio(String projectId, byte [] bytes, String sessionId,
String languageCode)
throws Exception {
// Set the session name using the sessionId (UUID) and projectID (my-project-id)
SessionName session = SessionName.of(projectId, sessionId);
System.out.println("Session Path: " + session.toString());
// Note: hard coding audioEncoding and sampleRateHertz for simplicity.
// Audio encoding of the audio content sent in the query request.
AudioEncoding audioEncoding = AudioEncoding.AUDIO_ENCODING_LINEAR_16;
int sampleRateHertz = 16000;
// Instructs the speech recognizer how to process the audio content.
InputAudioConfig inputAudioConfig = InputAudioConfig.newBuilder()
.setAudioEncoding(audioEncoding) // audioEncoding = AudioEncoding.AUDIO_ENCODING_LINEAR_16
.setLanguageCode(languageCode) // languageCode = "en-US"
.setSampleRateHertz(sampleRateHertz) // sampleRateHertz = 16000
.build();
// Build the query with the InputAudioConfig
QueryInput queryInput = QueryInput.newBuilder().setAudioConfig(inputAudioConfig).build();
// Read the bytes from the audio file
byte[] inputAudio = Files.readAllBytes(Paths.get("/home/rmg/Audio/book_a_room.wav"));
byte[] encodedAudio = Base64.encodeBase64(inputAudio);
// Build the DetectIntentRequest
DetectIntentRequest request = DetectIntentRequest.newBuilder()
.setSession("projects/"+projectId+"/agent/sessions/" + sessionId)
.setQueryInput(queryInput)
.setInputAudio(ByteString.copyFrom(encodedAudio))
.build();
// Performs the detect intent request
DetectIntentResponse response = sessionsClient.detectIntent(request);
// Display the query result
QueryResult queryResult = response.getQueryResult();
System.out.println("====================");
System.out.format("Query Text: '%s'\n", queryResult.getQueryText());
System.out.format("Detected Intent: %s (confidence: %f)\n",
queryResult.getIntent().getDisplayName(), queryResult.getIntentDetectionConfidence());
System.out.format("Fulfillment Text: '%s'\n", queryResult.getFulfillmentText());
return response;
}
Я пробовал использовать несколько форматов: wav (PCM 16 бит с несколькими частотами дискретизации) и FLAC, а также преобразовывать байты в base64 двумя различными способами, как описано здесь (с помощью кодаили консоль):
https://dialogflow.com/docs/reference/text-to-speech
Я даже протестировал с помощью .wav, представленного в этом примере, создав новое намерение в моем агенте под названием "забронировать комнату" с этой обучающей фразой.Он работает с использованием текста и звука из консоли диалогового потока, но работает только с текстом, а не с аудио из моего кода ... и я посылаю тот же wav, который они предоставляют!(код выше)
Я всегда получаю один и тот же ответ (QueryResult):
![enter image description here](https://i.stack.imgur.com/KRwOU.png)
Мне нужна подсказка или что-то, я 'Я полностью застрял здесь.Нет логов, нет ошибок в ответе ... но не работает.
Спасибо