37
37
public class AIHoloController {
38
38
private String theValue = "mirrorme" ;
39
39
private static final ScheduledExecutorService scheduler = Executors .newScheduledThreadPool (1 );
40
- private static final String API_URL = "http://129.x.x.x/v1/chat/completions?client=server" ;
40
+ private static final String API_URL = "http://129.x.x.x/v1/chat/completions?client=server" ;
41
41
private static final String AUTH_TOKEN = "Bearer asdf" ;
42
+ private static final String DEFAULT_LANGUAGE_CODE = "Bearer asdf" ;
43
+ private static final String DEFAULT_VOICE_NAME = "Bearer asdf" ;
42
44
43
45
@ Autowired
44
46
private DataSource dataSource ;
45
47
46
- private volatile long lastRequestTime = System .currentTimeMillis ();
48
+ private static final Object metahumanLock = new Object ();
49
+ private static boolean isRecentQuestionProcessed ;
47
50
48
51
public AIHoloController () {
49
52
System .out .println ("startInactivityMonitor..." );
@@ -52,18 +55,18 @@ public AIHoloController() {
52
55
53
56
private void startInactivityMonitor () {
54
57
scheduler .scheduleAtFixedRate (() -> {
55
- System .out .println ("about to say testing 1 2 3..." );
56
- sendToAudio2Face ("testing123-brazil.wav" );
57
- // long currentTime = System.currentTimeMillis();
58
- // if (currentTime - lastRequestTime > TimeUnit.MINUTES.toMillis(2)) {
59
- // sendToAudio2Face("testing123-brazil.wav");
60
- // lastRequestTime = currentTime; // Reset timer to prevent repeated execution
61
- // }
62
- }, 1 , 1 , TimeUnit .MINUTES );
58
+ if (isRecentQuestionProcessed ) {
59
+ System .out .println ("isRecentQuestionProcessed true so skipping the timecheck/keepalive" );
60
+ isRecentQuestionProcessed = false ;
61
+ }
62
+ String fileName = "currenttime.wav" ; //testing123-brazil.wav
63
+ TTSAndAudio2Face .processMetahuman (
64
+ fileName , TimeInWords .getTimeInWords (true ),
65
+ DEFAULT_LANGUAGE_CODE , DEFAULT_VOICE_NAME );
66
+ }, 1 , 15 , TimeUnit .MINUTES );
63
67
}
64
68
65
69
66
-
67
70
@ GetMapping ("/set" )
68
71
public String setValue (@ RequestParam ("value" ) String value ) {
69
72
theValue = value ;
@@ -94,7 +97,7 @@ public String getValue() {
94
97
static String sql = """
95
98
SELECT DBMS_CLOUD_AI.GENERATE(
96
99
prompt => ?,
97
- profile_name => 'AIHOLO ',
100
+ profile_name => 'VIDEO_GAMES ',
98
101
action => ?
99
102
) FROM dual
100
103
""" ;
@@ -151,10 +154,7 @@ public String play(@RequestParam("question") String question,
151
154
}
152
155
String fileName = "output.wav" ;
153
156
System .out .println ("about to TTS and sendAudioToAudio2Face for answer: " + answer );
154
- TTS (fileName , answer , languagecode , voicename );
155
- TTS ("hello-brazil.wav" , "olá" , languagecode , voicename );
156
- TTS ("testing123-brazil.wav" , "testando um, dois, três" , languagecode , voicename );
157
- sendToAudio2Face (fileName );
157
+ TTSAndAudio2Face .processMetahuman (fileName , answer , languagecode , voicename );
158
158
return answer ;
159
159
}
160
160
@@ -169,48 +169,6 @@ public String play(@RequestParam("question") String question,
169
169
170
170
171
171
172
- private void sendToAudio2Face (String fileName ) {
173
- RestTemplate restTemplate = new RestTemplate ();
174
- String baseUrl = "http://localhost:8011/A2F/Player/" ;
175
-
176
- String setRootPathUrl = baseUrl + "SetRootPath" ;
177
- Map <String , Object > rootPathPayload = new HashMap <>();
178
- rootPathPayload .put ("a2f_player" , "/World/audio2face/Player" );
179
- rootPathPayload .put ("dir_path" , "C:/Users/opc/src/github.com/paulparkinson/oracle-ai-for-sustainable-dev/java-ai" );
180
- sendPostRequest (restTemplate , setRootPathUrl , rootPathPayload );
181
-
182
- String setTrackUrl = baseUrl + "SetTrack" ;
183
- Map <String , Object > trackPayload = new HashMap <>();
184
- trackPayload .put ("a2f_player" , "/World/audio2face/Player" );
185
- trackPayload .put ("file_name" , fileName );
186
- trackPayload .put ("time_range" , new int [] { 0 , -1 });
187
- sendPostRequest (restTemplate , setTrackUrl , trackPayload );
188
-
189
- String playTrackUrl = baseUrl + "Play" ;
190
- Map <String , Object > playPayload = new HashMap <>();
191
- playPayload .put ("a2f_player" , "/World/audio2face/Player" );
192
- sendPostRequest (restTemplate , playTrackUrl , playPayload );
193
- }
194
-
195
- private void sendPostRequest (RestTemplate restTemplate , String url , Map <String , Object > payload ) {
196
- HttpHeaders headers = new HttpHeaders ();
197
- headers .setContentType (MediaType .APPLICATION_JSON );
198
- HttpEntity <Map <String , Object >> request = new HttpEntity <>(payload , headers );
199
-
200
- ResponseEntity <String > response = restTemplate .postForEntity (url , request , String .class );
201
- if (response .getStatusCode ().is2xxSuccessful ()) {
202
- System .out .println ("Successfully sent request to: " + url );
203
- } else {
204
- System .err .println ("Failed to send request to " + url + ". Response: " + response .getBody ());
205
- }
206
- }
207
-
208
-
209
-
210
-
211
-
212
-
213
-
214
172
public String executeSandbox (String cummulativeResult ) {
215
173
System .out .println ("isRag is true, using AI sandbox: " + cummulativeResult );
216
174
@@ -255,35 +213,6 @@ public String executeSandbox(String cummulativeResult) {
255
213
// `https://141.148.204.74:8444/aiholo/tts?textToConvert=${encodeURIComponent(textToConvert)}&languageCode=${encodeURIComponent(languageCode)}&ssmlGender=${encodeURIComponent(ssmlGender)}&voiceName=${encodeURIComponent(voiceName)}`;
256
214
257
215
258
- public void TTS (String fileName , String text , String languageCode , String voicename ) throws Exception {
259
- try (TextToSpeechClient textToSpeechClient = TextToSpeechClient .create ()) {
260
- System .out .println ("in TTS languagecode:" + languageCode + " voicename:" + voicename + " text:" + text );
261
- SynthesisInput input = SynthesisInput .newBuilder ().setText (
262
- // "最受欢迎的游戏是Pods Of Kon。").build();
263
- text ).build ();
264
- // "最も人気のあるビデオゲームは「Pods Of Kon」です。").build();
265
- VoiceSelectionParams voice =
266
- VoiceSelectionParams .newBuilder ()
267
- .setLanguageCode (languageCode ) //ja-JP, en-US, ...
268
- .setSsmlGender (SsmlVoiceGender .FEMALE ) // NEUTRAL, MALE
269
- // .setName("pt-BR-Wavenet-D") // tts-pt-BRFEMALEpt-BR-Wavenet-D_Bem-vindo
270
- .setName (voicename ) // "Kore" tts-pt-BRFEMALEpt-BR-Wavenet-D_Bem-vindo
271
- .build ();
272
-
273
- AudioConfig audioConfig =
274
- AudioConfig .newBuilder ()
275
- .setAudioEncoding (AudioEncoding .LINEAR16 ) // wav
276
- // .setAudioEncoding(AudioEncoding.MP3)
277
- .build ();
278
- SynthesizeSpeechResponse response =
279
- textToSpeechClient .synthesizeSpeech (input , voice , audioConfig );
280
- ByteString audioContents = response .getAudioContent ();
281
- try (OutputStream out = new FileOutputStream (fileName )) {
282
- out .write (audioContents .toByteArray ());
283
- System .out .println ("Audio content written to file:" + fileName );
284
- }
285
- }
286
- }
287
216
288
217
// `https://host:port/aiholo/tts?textToConvert=${encodeURIComponent(textToConvert)}&languageCode=${encodeURIComponent(languageCode)}&ssmlGender=${encodeURIComponent(ssmlGender)}&voiceName=${encodeURIComponent(voiceName)}`;
289
218
@ GetMapping ("/tts" )
0 commit comments