abhishekjoel commited on
Commit
758ab5f
·
verified ·
1 Parent(s): bca45f9

Update utils.py

Browse files
Files changed (1) hide show
  1. utils.py +9 -5
utils.py CHANGED
@@ -1,6 +1,7 @@
1
  import os
2
  from pydub import AudioSegment
3
  import openai
 
4
 
5
  def split_audio(file_path, chunk_length=10*60*1000):
6
  audio = AudioSegment.from_file(file_path)
@@ -17,16 +18,19 @@ def transcribe_audio(chunks):
17
  timestamps = []
18
  for idx, chunk in enumerate(chunks):
19
  with open(chunk, "rb") as audio_file:
20
- response = openai.Audio.transcribe("whisper-1", audio_file)
21
- transcriptions.append(response['text'])
 
 
 
 
 
 
22
  timestamps.append(f"Chunk {idx} - {idx * 10} min to {(idx + 1) * 10} min")
23
  return transcriptions, timestamps
24
 
25
  def generate_lesson_plan(transcriptions):
26
- # Combine transcriptions into a single text
27
  combined_transcript = " ".join(transcriptions)
28
-
29
- # Call ChatGPT to generate a lesson plan
30
  response = openai.ChatCompletion.create(
31
  model="gpt-4",
32
  messages=[
 
1
  import os
2
  from pydub import AudioSegment
3
  import openai
4
+ import tempfile
5
 
6
  def split_audio(file_path, chunk_length=10*60*1000):
7
  audio = AudioSegment.from_file(file_path)
 
18
  timestamps = []
19
  for idx, chunk in enumerate(chunks):
20
  with open(chunk, "rb") as audio_file:
21
+ # Transcribe using ChatGPT (Whisper functionality through chat)
22
+ response = openai.ChatCompletion.create(
23
+ model="gpt-4",
24
+ messages=[
25
+ {"role": "user", "content": f"Transcribe the following audio chunk: {chunk}"}
26
+ ]
27
+ )
28
+ transcriptions.append(response['choices'][0]['message']['content'])
29
  timestamps.append(f"Chunk {idx} - {idx * 10} min to {(idx + 1) * 10} min")
30
  return transcriptions, timestamps
31
 
32
  def generate_lesson_plan(transcriptions):
 
33
  combined_transcript = " ".join(transcriptions)
 
 
34
  response = openai.ChatCompletion.create(
35
  model="gpt-4",
36
  messages=[