-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for voice messages (#11)
Also: * Apply OOP for Chat, User objects * Improve logging * Re-use system message id
- Loading branch information
1 parent
6d1980d
commit 7486b25
Showing
14 changed files
with
388 additions
and
221 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from "./agent"; | ||
export * from "./speech"; | ||
export * from "./tool"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export type SpeechData = { | ||
blob: () => Promise<Blob>; | ||
url: string; | ||
}; | ||
|
||
export type Speech = { | ||
fromText(text: string): Promise<SpeechData>; | ||
toText(input: SpeechData): Promise<string>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { toFile } from "openai"; | ||
import { SpeechCreateParams } from "openai/resources/audio/speech"; | ||
import { TranscriptionCreateParams } from "openai/resources/audio/transcriptions"; | ||
|
||
import { SpeechData } from "@bubby/core/interfaces/ai"; | ||
import { openai } from "./openai"; | ||
|
||
export async function audioCreateTranscription( | ||
speechData: SpeechData | ||
): Promise<string> { | ||
const body: TranscriptionCreateParams = { | ||
file: await toFile(speechData), | ||
model: "whisper-1", | ||
}; | ||
const transcription = await openai.audio.transcriptions.create(body); | ||
console.log(JSON.stringify(transcription, null, 2)); | ||
return transcription.text; | ||
} | ||
|
||
export async function audioCreateSpeech(input: string): Promise<SpeechData> { | ||
const body: SpeechCreateParams = { | ||
input, | ||
model: "tts-1", | ||
response_format: "opus", | ||
voice: "alloy", | ||
}; | ||
return openai.audio.speech.create(body); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { Speech } from "@bubby/core/interfaces/ai"; | ||
import { audioCreateSpeech, audioCreateTranscription } from "./internal/audio"; | ||
|
||
export const speech: Speech = { | ||
fromText: async (text) => audioCreateSpeech(text), | ||
toText: (speechData) => audioCreateTranscription(speechData), | ||
}; |
Oops, something went wrong.