From 36da5dd849408d73ea0a91a6f763e761ab13ba86 Mon Sep 17 00:00:00 2001 From: I538344 Date: Wed, 5 Aug 2026 16:24:08 +0200 Subject: [PATCH 1/3] feat: [OpenAI] Improve realtime UI --- .../sdk/app/controllers/OpenAiController.java | 10 +- .../src/main/resources/static/index.html | 235 ++++++++++++------ .../src/main/resources/static/pcm-audio.js | 25 ++ .../resources/static/show-realtime-diagram.js | 20 -- .../main/resources/static/speech-to-speech.js | 169 ++++--------- .../main/resources/static/text-to-speech.js | 111 +++------ 6 files changed, 267 insertions(+), 303 deletions(-) create mode 100644 sample-code/spring-app/src/main/resources/static/pcm-audio.js delete mode 100644 sample-code/spring-app/src/main/resources/static/show-realtime-diagram.js diff --git a/sample-code/spring-app/src/main/java/com/sap/ai/sdk/app/controllers/OpenAiController.java b/sample-code/spring-app/src/main/java/com/sap/ai/sdk/app/controllers/OpenAiController.java index 9d15231e5..04eba5a70 100644 --- a/sample-code/spring-app/src/main/java/com/sap/ai/sdk/app/controllers/OpenAiController.java +++ b/sample-code/spring-app/src/main/java/com/sap/ai/sdk/app/controllers/OpenAiController.java @@ -40,7 +40,7 @@ public class OpenAiController { private static final ObjectMapper MAPPER = new ObjectMapper().setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY); - private Resource sampleQuestionPcm = new ClassPathResource("static/question.pcm"); + private final Resource sampleQuestionPcm = new ClassPathResource("static/question.pcm"); @GetMapping("/chatCompletion") @Nonnull @@ -53,9 +53,9 @@ Object chatCompletion( return response.getContent(); } - @GetMapping(value = "/realtime/smokeTestTextToSpeech", produces = "audio/pcm") + @GetMapping(value = "/realtime/textToSpeech", produces = "audio/pcm") @Nonnull - ResponseEntity smokeTestTextToSpeech() throws TimeoutException { + ResponseEntity textToSpeech() throws TimeoutException { final var respBody = ByteBuffer.allocate(300000); final var lock = new AtomicBoolean(false); final AudioOutputChannel audioOutput = @@ -85,9 +85,9 @@ ResponseEntity smokeTestTextToSpeech() throws TimeoutException { throw new TimeoutException("Timeout waiting for text to speech"); } - @GetMapping(value = "/realtime/smokeTestSpeechToSpeech", produces = "audio/pcm") + @GetMapping(value = "/realtime/speechToSpeech", produces = "audio/pcm") @Nonnull - ResponseEntity smokeTestSpeechToSpeech() throws TimeoutException { + ResponseEntity speechToSpeech() throws TimeoutException { final var respBody = ByteBuffer.allocate(800000); final var lock = new AtomicBoolean(false); final AudioOutputChannel audioOutput = diff --git a/sample-code/spring-app/src/main/resources/static/index.html b/sample-code/spring-app/src/main/resources/static/index.html index 6c1e668f8..4ccc3a20b 100644 --- a/sample-code/spring-app/src/main/resources/static/index.html +++ b/sample-code/spring-app/src/main/resources/static/index.html @@ -7,28 +7,33 @@