11
11
import oci
12
12
from oci .config import from_file
13
13
from oci .auth .signers .security_token_signer import SecurityTokenSigner
14
- from oci . ai_speech_realtime import (
15
- RealtimeClient ,
16
- RealtimeClientListener ,
14
+ from oci_ai_speech_realtime import (
15
+ RealtimeSpeechClient ,
16
+ RealtimeSpeechClientListener ,
17
17
RealtimeParameters ,
18
18
)
19
19
from aiohttp import web
27
27
compartment_id = os .getenv ('COMPARTMENT_ID' )
28
28
print (f"compartment_id: { compartment_id } " )
29
29
30
+ # oracle atp with mTls enabled, use Thick mode [oracledb.init_oracle_client] to load all libraries neeeded
31
+ # download from https://www.oracle.com/database/technologies/instant-client/winx64-64-downloads.html
32
+ # main doc for mTLS https://docs.oracle.com/en/cloud/paas/autonomous-database/serverless/adbsb/connecting-python-mtls.html
33
+ oracledb .init_oracle_client (lib_dir = r"C:\Users\Rodrigo Chafik\Downloads\instantclient-basic-windows.x64-23.7.0.25.01\instantclient_23_7" )
30
34
connection = oracledb .connect (
31
- user = "moviestream " ,
32
- password = "Welcome12345 " ,
33
- dsn = "selectaidb_high " ,
34
- config_dir = "/Users/pparkins/Downloads/Wallet_SelectAIDB " ,
35
- wallet_location = "/Users/pparkins/Downloads/Wallet_SelectAIDB " ,
36
- wallet_password = "Welcome12345 "
35
+ user = "aiuser " ,
36
+ password = "OracleATeam#2025 " ,
37
+ dsn = "chafik_high " ,
38
+ config_dir = r"D:\aTeam\Wallet_chafik " ,
39
+ wallet_location = r"D:\aTeam\Wallet_chafik " ,
40
+ wallet_password = "ateamOracle@2024 "
37
41
)
38
42
print (f"Successfully connected to Oracle Database Connection: { connection } " )
39
43
@@ -105,7 +109,7 @@ def play_audio(file_path):
105
109
print (f"Error playing audio: { e } " )
106
110
107
111
108
- class SpeechListener (RealtimeClientListener ):
112
+ class SpeechListener (RealtimeSpeechClientListener ):
109
113
def on_result (self , result ):
110
114
global cummulativeResult , isSelect , isNarrate , isShowSQL , isRunSQL , isExplainSQL , last_result_time
111
115
if result ["transcriptions" ][0 ]["isFinal" ]:
@@ -174,7 +178,7 @@ async def check_idle():
174
178
175
179
176
180
def authenticator ():
177
- config = from_file ("~/.oci/config" , "MYSPEECHAIPROFILE " )
181
+ config = from_file ("~/.oci/config" , "DEFAULT " )
178
182
with open (config ["security_token_file" ], "r" ) as f :
179
183
token = f .readline ()
180
184
private_key = oci .signer .load_private_key_from_file (config ["key_file" ])
@@ -199,7 +203,7 @@ def executeSelectAI():
199
203
200
204
query = """SELECT DBMS_CLOUD_AI.GENERATE(
201
205
prompt => :prompt,
202
- profile_name => 'AIHOLO ',
206
+ profile_name => 'GENAI ',
203
207
action => :action)
204
208
FROM dual"""
205
209
@@ -219,32 +223,36 @@ def executeSelectAI():
219
223
220
224
if selectai_action in ("showsql" , "runsql" , "explainsql" ):
221
225
return
222
- # API key-based authentication...
223
- config = oci .config .from_file ("~/.oci/config" , "DEFAULT" )
224
- speech_client = AIServiceSpeechClient (config )
225
-
226
- text_to_speech = SynthesizeSpeechDetails (
227
- text = f" { latest_answer } " ,
228
- is_stream_enabled = False ,
229
- configuration = oci .ai_speech .models .TtsOracleConfiguration (
230
- model_family = "ORACLE" ,
231
- # Brian Annabelle Bob Stacy Phil Cindy Brad
232
- model_details = oci .ai_speech .models .TtsOracleTts2NaturalModelDetails (voice_id = "Brian" ),
233
- speech_settings = oci .ai_speech .models .TtsOracleSpeechSettings (
234
- speech_mark_types = ["WORD" ]
235
- ),
236
- )
237
- )
238
-
239
- response = speech_client .synthesize_speech (synthesize_speech_details = text_to_speech )
240
-
241
- with open ("TTSoutput.wav" , "wb" ) as audio_file :
242
- audio_file .write (response .data .content )
226
+ # API key-based authentication, using phoenix OCI Region - https://docs.oracle.com/en-us/iaas/Content/speech/using/speech.htm#ser-limits
227
+ config = oci .config .from_file ("~/.oci/config" , "TESTES" )
228
+
229
+ ai_speech_client = oci .ai_speech .AIServiceSpeechClient (config )
230
+ synthesize_speech_response = ai_speech_client .synthesize_speech (
231
+ synthesize_speech_details = oci .ai_speech .models .SynthesizeSpeechDetails (
232
+ text = f" { latest_answer } " ,
233
+ is_stream_enabled = True ,
234
+ compartment_id = compartment_id ,
235
+ configuration = oci .ai_speech .models .TtsOracleConfiguration (
236
+ model_family = "ORACLE" ,
237
+ model_details = oci .ai_speech .models .TtsOracleTts1StandardModelDetails (
238
+ model_name = "TTS_1_STANDARD" ,
239
+ voice_id = "Bob" ),
240
+ speech_settings = oci .ai_speech .models .TtsOracleSpeechSettings (
241
+ text_type = "SSML" ,
242
+ sample_rate_in_hz = 28000 ,
243
+ output_format = "PCM" ,
244
+ speech_mark_types = ["WORD" ])),
245
+ audio_config = oci .ai_speech .models .TtsBaseAudioConfig (
246
+ config_type = "BASE_AUDIO_CONFIG" )
247
+ ) )
248
+
249
+ with open ("TTSoutput.pcm" , "wb" ) as audio_file :
250
+ audio_file .write (synthesize_speech_response .data .content )
243
251
244
252
print ("Speech synthesis completed and saved as TTSoutput.wav" )
245
253
246
254
# Play the generated speech
247
- play_audio ("TTSoutput.wav " )
255
+ play_audio ("TTSoutput.pcm " )
248
256
249
257
except Exception as e :
250
258
print (f"An error occurred: { e } " )
@@ -271,8 +279,8 @@ async def handle_request(request):
271
279
)
272
280
realtime_speech_parameters .final_silence_threshold_in_ms = 2000
273
281
274
- realtime_speech_url = "wss://realtime.aiservice.us-phoenix -1.oci.oraclecloud.com"
275
- client = RealtimeClient (
282
+ realtime_speech_url = "wss://realtime.aiservice.us-ashburn -1.oci.oraclecloud.com"
283
+ client = RealtimeSpeechClient (
276
284
config = config ,
277
285
realtime_speech_parameters = realtime_speech_parameters ,
278
286
listener = SpeechListener (),
@@ -281,16 +289,6 @@ async def handle_request(request):
281
289
compartment_id = compartment_id ,
282
290
)
283
291
284
- # Instance, resource principal, or session token-based authentication (as shown below) can also be used
285
- # client = RealtimeClient(
286
- # config=config,
287
- # realtime_speech_parameters=realtime_speech_parameters,
288
- # listener=SpeechListener(),
289
- # service_endpoint=realtime_speech_url,
290
- # signer=authenticator(),
291
- # compartment_id=compartment_id,
292
- # )
293
-
294
292
loop .create_task (send_audio (client ))
295
293
loop .create_task (check_idle ())
296
294
0 commit comments