Skip to content

Commit f34cfb8

Browse files
authored
Merge pull request #48 from paulparkinson/main
various mods to update speech select ai and ai holograms
2 parents 0036317 + 3313232 commit f34cfb8

File tree

160 files changed

+99377
-10
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

160 files changed

+99377
-10
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Set environment variable
2+
$env:COMPARTMENT_ID = "ocid1.compartment.oc1..aaaaaaaafnah3ogykjsg34qruhixhb2drls6zhsejzm7mubi2i5qj66slcoq"
3+
$env:PEM_PASSPHRASE = "Welcome12345"
4+
5+
# Authenticate OCI session
6+
#oci session authenticate --region us-phoenix-1 --profile-name MYSPEECHAIPROFILE
7+
8+
# Run Python script
9+
#python python-realtimespeech-selectai/src/RealtimeSpeechSelectAI.py
10+
python python-realtimespeech-selectai/src/InteractiveAIHologramsWebRequestVersion.py

interactive-ai-holograms/aiholo.ps1

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Set environment variable
2+
$env:COMPARTMENT_ID = "ocid1.compartment.oc1..aaaaaaaafnah3ogykjsg34qruhixhb2drls6zhsejzm7mubi2i5qj66slcoq"
3+
$env:PEM_PASSPHRASE = "Welcome12345"
4+
5+
# Authenticate OCI session
6+
#oci session authenticate --region us-phoenix-1 --profile-name MYSPEECHAIPROFILE
7+
8+
# Run Python script
9+
#python python-realtimespeech-selectai/src/RealtimeSpeechSelectAI.py
10+
# python python-realtimespeech-selectai/src/InteractiveAIHolograms.py
11+
python python-realtimespeech-selectai/src/InteractiveAIHologramsRest.py

interactive-ai-holograms/auth.ps1

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Set the OCI region environment variable
2+
$env:OCI_CLI_REGION = "us-phoenix-1"
3+
4+
# Define the profile name to be used
5+
$ProfileName = "MYSPEECHAIPROFILE`r`n"
6+
7+
# Start the OCI session authenticate command and try to pipe in the profile name
8+
$ProfileName | oci session authenticate --region $env:OCI_CLI_REGION
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
module.exports = {
2+
"env": {
3+
"es15": true,
4+
"node": true
5+
},
6+
"extends": [
7+
"eslint:recommended",
8+
"plugin:@typescript-eslint/recommended"
9+
],
10+
"overrides": [
11+
],
12+
"parser": "@typescript-eslint/parser",
13+
"parserOptions": {
14+
"ecmaVersion": "latest",
15+
"sourceType": "module"
16+
},
17+
"plugins": [
18+
"@typescript-eslint"
19+
],
20+
"rules": {
21+
},
22+
"exclude": ["node_modules"]
23+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
registry="https://registry.npmjs.org/"
2+
@types:registry="https://registry.npmjs.org/"
3+
strict-ssl=false
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Example Client for the Realtime Speech Web SDK
2+
3+
This is an example client that demonstrates how to connect to the OCI Realtime Speech service, and how to handle results.
4+
5+
This has 2 components, a server and a react client. The server has access to OCI credentials/auth providers, and makes a call to the speech service to fetch a token. This token is passed to the web client to securely connect directly to the realtime speech service.
6+
7+
Follow these instructions to build/test the client.
8+
9+
## Parameter Changes
10+
11+
You'll need to fill in the following parameters.
12+
13+
In `index.ts`:
14+
15+
- `compartmentId`: The target compartment ID in which you want to use the realtime speec service. If you're using customizations, make they are in the same compartment.
16+
- `region`: Your target region e.g. "us-ashburn-1"
17+
- `provider`: Your authentication details provider.
18+
19+
In `react-client/src/App.tsx`:
20+
21+
- `realtimeClientParameters`: This is the place to declare partial/final silence thresholds, language, model domain (generic/medical), customizations, etc.
22+
23+
For customizations, populate the array with the OCIDs of valid, active customizations.
24+
25+
See this for more: https://docs.oracle.com/en-us/iaas/api/#/en/speech/20220101/datatypes/RealtimeParameters
26+
27+
28+
## Build Instructions
29+
30+
You can run the following to build both the server and client:
31+
```bash
32+
npm run setup
33+
```
34+
35+
If you want to buld the client the client/server separately, feel free to run `npm install` in their respective directories.
36+
37+
38+
## Run Instructions
39+
40+
You can do the following to run the example. It is recommended to run both the server and client simultaneously.
41+
42+
```bash
43+
npm start
44+
```
45+
46+
There are a few more start scripts available:
47+
48+
- `start:server`: Starts just the server
49+
- `start:dev`: Starts in dev mode
50+
- `start:client`: Starts just the web (React) client
51+
52+
Both the build/run commands should be run from the content root.
53+
54+
Once you start both the server and the react client, you should be able to load the client on your browser at `http://localhost:4884`. The server is started at `http://localhost:8448`
55+
56+
Press "Start Session" to begin the transcription. You should be able to see the results on the screen.
57+
58+
"Request Final Results" is a command that can be sent to the speech service to return final results instantly. Based on the partial/final silence thresholds defined in the realtime parameters in the react client, results may take time to arrive. This is a way of receiving the results if you need to close the client, without having to wait for the stabilized final results to arrive.
59+
60+
61+
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import express from "express";
2+
import cors from "cors";
3+
import bodyParser from "body-parser";
4+
import * as common from "oci-common";
5+
import * as aispeech from "oci-aispeech";
6+
import https from 'https';
7+
import fs from 'fs';
8+
9+
const app = express();
10+
const port = 8448;
11+
12+
// SSL Certificate options with specified paths
13+
const options = {
14+
key: fs.readFileSync('C:\\aiholo-app\\localhost-key.pem'), // Path to your private key
15+
cert: fs.readFileSync('C:\\aiholo-app\\localhost.pem') // Path to your certificate
16+
};
17+
18+
// Configure CORS to allow requests from your specific client origin
19+
// app.use(cors({
20+
// origin: 'http://130.61.51.75:4884', // Adjust this to match the origin you are accessing the server from
21+
// credentials: true // Allows cookies and credentials to be sent along with the requests
22+
// }));
23+
24+
app.use(cors({
25+
origin: ['https://130.61.51.75:4884'],
26+
credentials: true,
27+
methods: ['GET', 'POST'],
28+
allowedHeaders: ['Content-Type', 'Authorization']
29+
}));
30+
31+
32+
// The OCID of the compartment for authentication and authorization
33+
const compartmentId = "ocid1.compartment.oc1..aaaaaaaafnah3ogykjsg34qruhixhb2drls6zhsejzm7mubi2i5qj66slcoq";
34+
35+
// Set the region for OCI services
36+
const region = "us-phoenix-1";
37+
const provider = new common.SessionAuthDetailProvider("C:/Users/opc/.oci/config", "MYSPEECHAIPROFILE");
38+
39+
/**
40+
* Generates a real-time session token using Oracle Cloud Infrastructure (OCI) AI Speech Service.
41+
* Configures the OCI client with a specific region and compartment ID, then requests a real-time session token.
42+
*
43+
* @returns {Promise<string>} The real-time session token generated by the AI Speech Service.
44+
* @throws {Error} If the request to generate the session token fails.
45+
*/
46+
async function getRealtimeToken() {
47+
provider.setRegion(region);
48+
const speechClient = new aispeech.AIServiceSpeechClient({ authenticationDetailsProvider: provider });
49+
50+
const createRealtimeSessionTokenDetails = {
51+
compartmentId: compartmentId,
52+
};
53+
54+
const createRealtimeSessionTokenRequest: aispeech.requests.CreateRealtimeSessionTokenRequest = {
55+
createRealtimeSessionTokenDetails: createRealtimeSessionTokenDetails,
56+
};
57+
58+
const createRealtimeSessionTokenResponse = await speechClient.createRealtimeSessionToken(createRealtimeSessionTokenRequest);
59+
console.log("Token generated: ", createRealtimeSessionTokenResponse);
60+
return createRealtimeSessionTokenResponse.realtimeSessionToken;
61+
}
62+
63+
app.use(bodyParser.json());
64+
65+
app.get("/authenticate", async (req, res) => {
66+
try {
67+
const token = await getRealtimeToken();
68+
console.log("Token Response: ", token);
69+
res.send(token);
70+
} catch (error) {
71+
console.error("createRealtimeSessionToken Failed with error: ", error);
72+
res.status(500).send(error.toString());
73+
}
74+
});
75+
76+
app.get("/region", (req, res) => {
77+
console.log('Received headers:', req.headers);
78+
res.send({ region: region });
79+
});
80+
81+
// Using HTTPS server instead of the standard HTTP server
82+
https.createServer(options, app).listen(port, '0.0.0.0', () => {
83+
console.log(`https server running at https://0.0.0.0:${port}`);
84+
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"ignore": [
3+
"node_modules"
4+
]
5+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"watch": [
3+
"index.ts",
4+
"index.html"
5+
],
6+
"ext": ".ts,.js",
7+
"ignore": [],
8+
"exec": "npx ts-node ./index.ts"
9+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
registry="https://registry.npmjs.org/"
2+
@types:registry="https://registry.npmjs.org/"
3+
strict-ssl=false

0 commit comments

Comments
 (0)