File tree Expand file tree Collapse file tree 3 files changed +32
-0
lines changed
src/main/java/co/yml/ychat/jvm Expand file tree Collapse file tree 3 files changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -106,4 +106,19 @@ curl -X POST \
106106 -H "Content-Type: multipart/form-data" \
107107 -F "file=@/path/to/audio/file" \
108108 "http://localhost:8080/api/ychat/audio/transcriptions"
109+ ```
110+
111+ ### Audio Translations Endpoint
112+
113+ This endpoint translates audio into English
114+
115+ ##### Endpoint: http://localhost:[port_number ] /api/ychat/audio/translations
116+
117+ ##### Example:
118+
119+ ```
120+ curl -X POST \
121+ -H "Content-Type: multipart/form-data" \
122+ -F "file=@/path/to/audio/file" \
123+ "http://localhost:8080/api/ychat/audio/translations"
109124```
Original file line number Diff line number Diff line change @@ -74,6 +74,14 @@ public ResponseEntity<String> audioTranscriptions(
7474 return ResponseEntity .ok (result );
7575 }
7676
77+ @ PostMapping ("audio/translations" )
78+ public ResponseEntity <String > audioTranslations (
79+ @ RequestParam ("file" ) MultipartFile multipartFile
80+ ) throws Exception {
81+ String result = YChatService .getAudioTranscription (multipartFile );
82+ return ResponseEntity .ok (result );
83+ }
84+
7785 private static class Defaults {
7886 static final String COMPLETION_INPUT = "Say this is a test." ;
7987 static final String CHAT_COMPLETION_INPUT = "Tell me one strength exercise" ;
Original file line number Diff line number Diff line change @@ -76,6 +76,15 @@ public String getAudioTranscription(MultipartFile multipartFile) throws Exceptio
7676 return future .get ();
7777 }
7878
79+ public String getAudioTranslations (MultipartFile multipartFile ) throws Exception {
80+ final CompletableFuture <String > future = new CompletableFuture <>();
81+ String filename = Optional .ofNullable (multipartFile .getOriginalFilename ())
82+ .orElseThrow (() -> new IllegalStateException ("Filename not found" ));
83+ byte [] bytes = multipartFile .getBytes ();
84+ ychat .audioTranslations ().execute (filename , bytes , new CompletionCallbackResult <>(future ));
85+ return future .get ();
86+ }
87+
7988 private static class CompletionCallbackResult <T > implements YChat .Callback <T > {
8089
8190 private final CompletableFuture <T > future ;
You can’t perform that action at this time.
0 commit comments