-
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Support for Groq's Whisper API for audio transcription * Update README.md to include support for groq's Whisper API for audio transcription * Update README.md to include support for groq's Whisper API for audio transcription * update readme
- Loading branch information
Showing
7 changed files
with
102 additions
and
12 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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,34 @@ | ||
import fs from "fs"; | ||
import { openai } from "../../clients/openai"; | ||
import { TRANSCRIPTION_LANGUAGE } from "../../constants"; | ||
import Groq from "groq-sdk"; | ||
|
||
export async function handleAudioMessageWithGroqApi(wavPath: string) { | ||
console.log("Transcribing audio with Groq API"); | ||
try { | ||
const groq = new Groq() | ||
|
||
const transcriptionOptions: any = { | ||
file: fs.createReadStream(wavPath), | ||
model: "whisper-large-v3", | ||
//prompt: "Specify context or spelling", // Optional | ||
response_format: "json", // Optional | ||
temperature: 0.0, // Optional | ||
}; | ||
|
||
if (TRANSCRIPTION_LANGUAGE !== "auto") { | ||
transcriptionOptions.language = TRANSCRIPTION_LANGUAGE; | ||
} | ||
|
||
const transcription = | ||
await groq.audio.transcriptions.create(transcriptionOptions); | ||
return transcription.text; | ||
} finally { | ||
// Regardless of success or failure, attempt to delete the WAV file | ||
try { | ||
fs.unlinkSync(wavPath); // Delete the WAV file | ||
} catch (error) { | ||
console.error("Error deleting WAV file:", error); | ||
} | ||
} | ||
} |
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