🚀 Future-Proof & Clickable – This doc is structured for quick navigation, visual clarity, and easy updates.
- 🔑 OpenAI API Key Usage
- 🎙️ Whisper AI – Speech to Text
- 📦 Why Install
multipart - 🆕 Using Latest OpenAI Version
- ⚡ Quick Reference Table
os.getenv()Reads Env Vars – FetchesOPEN_AI_API_KEYfrom environment variables.- Must Export It 🔐 – Before running:
export OPEN_AI_API_KEY="your_api_key" ## 🎙️ 2. Whisper AI – Speech to Text
- What is Whisper? 🎙️ – OpenAI’s automatic speech recognition (ASR) model for converting audio to text.
- Usage in Code 💻:
import openai openai.api_key = "your_api_key" audio_file = open("your_audio.mp3", "rb") transcript = openai.Audio.transcribe("whisper-1", audio_file) print(transcript["text"])
- Purpose – Parses
multipart/form-datafor handling file uploads in FastAPI and similar frameworks. - Example:
from fastapi import FastAPI, File, UploadFile app = FastAPI() @app.post("/upload/") async def upload(file: UploadFile = File(...)): return {"filename": file.filename}
- API Key Change 🔑 – Old:
openai.apikey❌ → New:OpenAI(api_key=...)✅ - File Handling 📂 – Files are temporarily saved before being sent to the API.
- Method Update 🛠️ – Old:
transcribe()❌ → New:client.audio.transcriptions.create(...)✅ - FastAPI Integration ⚡ –
UploadFile = File(...)ensures propermultipart/form-datahandling. - Future-Proofing 🚀 – v1+ syntax prevents deprecation issues and keeps code up-to-date.
| Section | Topic | Key Command / Code | Notes |
|---|---|---|---|
| 1 | OpenAI API Key Usage | export OPEN_AI_API_KEY="your_api_key" |
Set in terminal before running app |
| 2 | Whisper AI – Speech to Text | openai.Audio.transcribe("whisper-1", audio_file) |
Works with .mp3, .wav, .m4a, etc. |
| 3 | Install multipart |
pip install python-multipart |
Needed for file uploads in FastAPI |
| 4 | Latest OpenAI Version | OpenAI(api_key=...) & client.audio.transcriptions.create(...) |
Updated v1+ SDK syntax |
