Spaces:
Runtime error
Runtime error
Update transcription_diarization.py
Browse files- transcription_diarization.py +15 -5
transcription_diarization.py
CHANGED
@@ -11,6 +11,7 @@ from collections import defaultdict
|
|
11 |
import numpy as np
|
12 |
from openai import OpenAI
|
13 |
from config import openai_api_key
|
|
|
14 |
|
15 |
client = OpenAI(api_key=openai_api_key)
|
16 |
|
@@ -47,14 +48,23 @@ def transcribe_audio(audio_path, language):
|
|
47 |
response_format="verbose_json"
|
48 |
)
|
49 |
|
50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
transcription_chunks = []
|
52 |
|
53 |
-
for segment in transcript.segments:
|
54 |
transcription_chunks.append({
|
55 |
-
"start": segment.start,
|
56 |
-
"end": segment.end,
|
57 |
-
"text": segment.text
|
58 |
})
|
59 |
|
60 |
return transcription_txt, transcription_chunks
|
|
|
11 |
import numpy as np
|
12 |
from openai import OpenAI
|
13 |
from config import openai_api_key
|
14 |
+
import json
|
15 |
|
16 |
client = OpenAI(api_key=openai_api_key)
|
17 |
|
|
|
48 |
response_format="verbose_json"
|
49 |
)
|
50 |
|
51 |
+
# Print the type and content of the response
|
52 |
+
print("Type of transcript:", type(transcript))
|
53 |
+
print("Content of transcript:")
|
54 |
+
print(json.dumps(transcript, indent=2, default=str))
|
55 |
+
|
56 |
+
# Convert the response to a dictionary if it's not already
|
57 |
+
if not isinstance(transcript, dict):
|
58 |
+
transcript = transcript.model_dump()
|
59 |
+
|
60 |
+
transcription_txt = transcript.get("text", "")
|
61 |
transcription_chunks = []
|
62 |
|
63 |
+
for segment in transcript.get("segments", []):
|
64 |
transcription_chunks.append({
|
65 |
+
"start": segment.get("start", 0),
|
66 |
+
"end": segment.get("end", 0),
|
67 |
+
"text": segment.get("text", "")
|
68 |
})
|
69 |
|
70 |
return transcription_txt, transcription_chunks
|