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
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1" />
6+
<meta name="theme-color" content="#000000" />
7+
<meta name="description" content="SDK Latency Testing Tool" />
8+
<link
9+
rel="stylesheet"
10+
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
11+
integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T"
12+
crossorigin="anonymous" />
13+
<title>OCI AI Speech</title>
14+
<link rel="icon" href="https://www.oracle.com/asset/web/favicons/favicon-32.png" sizes="32x32" />
15+
<link rel="icon" href="https://www.oracle.com/asset/web/favicons/favicon-128.png" sizes="128x128" />
16+
<link rel="icon" href="https://www.oracle.com/asset/web/favicons/favicon-192.png" sizes="192x192" />
17+
<link rel="apple-touch-icon" href="https://www.oracle.com/asset/web/favicons/favicon-120.png" sizes="120x120" />
18+
<link rel="apple-touch-icon" href="https://www.oracle.com/asset/web/favicons/favicon-152.png" sizes="152x152" />
19+
<link rel="apple-touch-icon" href="https://www.oracle.com/asset/web/favicons/favicon-180.png" sizes="180x180" />
20+
</head>
21+
<body>
22+
<noscript>You need to enable JavaScript to run this app.</noscript>
23+
<div id="root"></div>
24+
<!--
25+
This HTML file is a template.
26+
If you open it directly in the browser, you will see an empty page.
27+
28+
You can add webfonts, meta tags, or analytics to this file.
29+
The build step will place the bundled scripts into the <body> tag.
30+
31+
To begin the development, run `npm start` or `yarn start`.
32+
To create a production bundle, use `npm run build` or `yarn build`.
33+
-->
34+
</body>
35+
</html>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# https://www.robotstxt.org/robotstxt.html
2+
User-agent: *
3+
Disallow:
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const express = require('express');
2+
const https = require('https');
3+
const fs = require('fs');
4+
const path = require('path');
5+
const app = express();
6+
7+
const PORT = 4884; // Port number for your HTTPS server
8+
const options = {
9+
key: fs.readFileSync('C:\\aiholo-app\\localhost-key.pem'), // Path to your private key
10+
cert: fs.readFileSync('C:\\aiholo-app\\localhost.pem') // Path to your certificate
11+
};
12+
13+
// Serve static files from the React build directory
14+
app.use(express.static(path.join(__dirname, 'build')));
15+
16+
// All routes should redirect to the index.html
17+
app.get('*', (req, res) => {
18+
res.sendFile(path.join(__dirname, 'build', 'index.html'));
19+
});
20+
21+
https.createServer(options, app).listen(PORT, () => {
22+
console.log(`Server running on https://130.61.51.75:${PORT}`);
23+
});
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import React from "react";
2+
import "./App.css";
3+
// Import additional components and hooks
4+
import { useState } from 'react';
5+
6+
function App() {
7+
// Existing states and other code...
8+
9+
// Add state for the text field value
10+
const [textFieldValue, setTextFieldValue] = useState('');
11+
12+
// Function to handle HTTP call when button is clicked
13+
const handleCallSelectAI = async () => {
14+
const url = `http://130.61.51.75/data?question=${encodeURIComponent(textFieldValue)}`;
15+
try {
16+
const response = await fetch(url);
17+
const data = await response.json();
18+
console.log('Response from AI:', data);
19+
} catch (error) {
20+
console.error('Error fetching AI data:', error);
21+
}
22+
};
23+
24+
// Render function with added text field and button
25+
return (
26+
<div className="App">
27+
{/* Existing components... */}
28+
<div>
29+
<input
30+
type="text"
31+
value={textFieldValue}
32+
onChange={(e) => setTextFieldValue(e.target.value)}
33+
placeholder="Enter your question"
34+
/>
35+
<button onClick={handleCallSelectAI}>Call Select AI</button>
36+
</div>
37+
{/* Existing rendering logic... */}
38+
</div>
39+
);
40+
}
41+
42+
export default App;
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
** MyWidget version 1.0.
3+
**
4+
** Copyright (c) 2015 WidgetCo, Inc.
5+
** Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
6+
*/
7+
8+
.App {
9+
text-align: left;
10+
padding: 20px;
11+
}
12+
13+
.App-logo {
14+
height: 40vmin;
15+
pointer-events: none;
16+
}
17+
18+
@media (prefers-reduced-motion: no-preference) {
19+
.App-logo {
20+
animation: App-logo-spin infinite 20s linear;
21+
}
22+
}
23+
24+
.App-header {
25+
background-color: #282c34;
26+
min-height: 100vh;
27+
display: flex;
28+
flex-direction: column;
29+
align-items: center;
30+
justify-content: center;
31+
font-size: calc(10px + 2vmin);
32+
color: white;
33+
}
34+
35+
.App-link {
36+
color: #61dafb;
37+
}
38+
39+
@keyframes App-logo-spin {
40+
from {
41+
transform: rotate(0deg);
42+
}
43+
44+
to {
45+
transform: rotate(360deg);
46+
}
47+
}

0 commit comments

Comments
 (0)