#Whisper API only transcribing first few seconds for audio recorded in safari browser in mac device.
1 messages · Page 1 of 1 (latest)
Have you confirmed that your audio file indeed contains all of the audio that you need transcribed? Is the audio file in the expected correct format for the API? @wild shard
@visual solar yes. I'm storing the audio in AWS S3 after sending it to the whisper API for transcription. I downloaded the mp4 from AWS S3 to verify this. What I found was the audio in mp4 contains all the expected content. But the whisper API only returns transcription of just an initial 1 or 2 seconds.
Can you share the surrouding code before and after the whisper transcription request?
Sure
```
audio_file = serializer.validated_data['audio_file'] ## blod data from frontend
stringified_messages = request.data.get('messages')
file_name = request.data.get('file_name')
messages = json.loads(stringified_messages)
try:
temp_file_path = handle_temporary_storage(
audio_file, 'audio', file_name)
except Exception as e:
return Response({"detail": str(e)}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
try:
user_message = AssessmentsAPI().transcribe_audio(temp_file_path)
```
```
def handle_temporary_storage(file, folder, key):
try:
directory_path = os.path.join(MEDIA_ROOT, folder)
if not os.path.exists(directory_path):
os.makedirs(directory_path)
file_path = os.path.join(directory_path, key)
with open(file_path, 'wb+') as destination:
for chunk in file.chunks():
destination.write(chunk)
return file_path
except Exception as e:
logger.error(f"Error handling temporary storage for file: {e}")
raise
```
```
@staticmethod
def transcribe_audio(file_path):
with open(file_path, 'rb') as audio_file:
transcript = client.audio.transcriptions.create(
model="whisper-1",
file=audio_file
)
return transcript.text
```