Spaces:
Build error
Build error
Create utils.py
Browse files12345678910111213141516171819202122232425262728293031323334353637import osfrom pydub import AudioSegmentimport openai
def split_audio(file_path, chunk_length=10*60*1000): audio = AudioSegment.from_file(file_path) chunks = [] for start in range(0, len(audio), chunk_length): chunk = audio[start:start + chunk_length] chunk_file = f"chunk_{start // chunk_length}.mp3" chunk.export(chunk_file, format="mp3") chunks.append(chunk_file) return chunks
def transcribe_audio(chunks): transcriptions = [] timestamps = [] for idx, chunk in enumerate(chunks): with open(chunk, "rb") as audio_file: response = openai.Audio.transcribe("whisper-1", audio_file) transcriptions.append(response['text']) timestamps.append(f"Chunk {idx} - {idx * 10} min to {(idx + 1) * 10} min") return transcriptions, timestamps
def generate_lesson_plan(transcriptions): # Combine transcriptions into a single text combined_transcript = " ".join(transcriptions) # Call ChatGPT to generate a lesson plan response = openai.ChatCompletion.create( model="gpt-4", messages=[ {"role": "user", "content": f"Generate a detailed lesson plan based on the following transcript:\n\n{combined_transcript}"} ] ) lesson_plan = response['choices'][0]['message']['content'] return lesson_planutils.pyAdded+37