Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions contributed/conversationalAI/assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,10 @@ const assets = {
{ name:"Alloy", id:"alloy" },
{ name:"Ash", id:"ash" },
{ name:"Ballad", id:"ballad" },
{ name:"Cedar", id:"cedar" },
{ name:"Coral", id:"coral" },
{ name:"Echo", id:"echo" },
{ name:"Marin", id:"marin" },
{ name:"Sage", id:"sage" },
{ name:"Shimmer", id:"shimmer" },
{ name:"Verse", id:"verse" },
Expand Down
2 changes: 1 addition & 1 deletion examples/io/tcp/websocketsclient/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ const ws = new WebSocketClient({
...device.network.wss,
host: "api.openai.com",
path: "/v1/realtime?model=gpt-4o-realtime-preview-2024-10-01",
path: "/v1/realtime?model=gpt-realtime",
port: 443,
headers: [
["OpenAI-Beta", "realtime=v1"],
["Authorization", `Bearer ${apiKey}`],
],
onReadable(count, options) {
Expand Down
47 changes: 30 additions & 17 deletions modules/network/services/chatAudioIO/workers/openAIRealtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@ class OpenAIRealTimeModel extends ChatWebSocketWorker {
constructor(options) {
super(options);
this.host = "api.openai.com";
this.path = `/v1/realtime?model=gpt-4o-realtime-preview-2024-10-01`;
this.path = `/v1/realtime?model=gpt-realtime`;
this.headers = [
["OpenAI-Beta", "realtime=v1"],
["Authorization", `Bearer ${config.openAIKey}`]
];
this.audioPrefix = audioPrefix;
Expand All @@ -47,18 +46,27 @@ class OpenAIRealTimeModel extends ChatWebSocketWorker {
});
this.session = {
instructions,
voice,
turn_detection: {
type: "server_vad",
threshold: 0.5,
prefix_padding_ms: 300,
silence_duration_ms: 500,
create_response: true
audio: {
input: {
format: { type: 'audio/pcma' },
turn_detection: {
type: "server_vad",
threshold: 0.5,
prefix_padding_ms: 300,
silence_duration_ms: 500,
create_response: true
},
transcription: {
model: 'whisper-1',
}
},
output: {
voice
}
},
input_audio_format: "g711_alaw",
input_audio_transcription: { model: 'whisper-1' },
tools,
tool_choice: "auto",
type: "realtime",
}
}
generateId(prefix, length = 21) {
Expand All @@ -71,7 +79,7 @@ class OpenAIRealTimeModel extends ChatWebSocketWorker {
return `${prefix}${str}`;
}
isBase64(result, current, name) {
return (result?.type == "response.audio.delta") && (name == "delta");
return (result?.type == "response.output_audio.delta") && (name == "delta");
}
sendAudio(message) {
const buffer = new Uint8Array(this.inputBuffer, message.offset, message.size);
Expand All @@ -90,6 +98,9 @@ class OpenAIRealTimeModel extends ChatWebSocketWorker {
},
event_id: this.generateId('event_'),
});
this.sendJSON({
type: 'response.create',
})
}
sendText(message) {
this.sendJSON({
Expand Down Expand Up @@ -124,20 +135,22 @@ class OpenAIRealTimeModel extends ChatWebSocketWorker {
'input_audio_buffer.committed'(message) {
this.post("listen");
}
'response.audio_transcript.delta'(message) {
'response.output_audio_transcript.delta'(message) {
this.postMessage({ id:"receiveOutputText", text:message.delta, more:true });
}
'response.audio_transcript.done'(message) {
'response.output_audio_transcript.done'(message) {
this.postMessage({ id:"receiveOutputText", text:"" });
}
'response.created'(message) {
this.postMessage({ id:"receiveInputText", text:"", more:true });
this.postMessage({ id:"receiveOutputText", text:"", more:true });
}
'response.done'(message) {
this.parser.copy(this.silence);
this.parser.done();
this.post("speak");
if(message.response?.output[0]?.type === 'messaege') {
this.parser.copy(this.silence);
this.parser.done();
this.post("speak");
}
}
'response.output_item.done'(message) {
const { item } = message;
Expand Down