Skip to content

Commit

Permalink
update the return for video
Browse files Browse the repository at this point in the history
  • Loading branch information
PascalSun committed Jul 24, 2024
1 parent 05e4127 commit 6bb1ef3
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions API/hardware/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,15 +272,15 @@ def client_audio(request, audio_id):
)

if (settings.STORAGE_SOLUTION == settings.STORAGE_SOLUTION_S3) or (
settings.STORAGE_SOLUTION == settings.STORAGE_SOLUTION_API
settings.STORAGE_SOLUTION == settings.STORAGE_SOLUTION_API
):

# we will grab it from the s3 and return it
s3_client = settings.BOTO3_SESSION.client("s3")
# construct the key and then create the pre-signed url
s3_key = f"Listener/audio/{audio_obj.uid}/{audio_obj.audio_file}"
local_file = (
settings.CLIENT_MEDIA_ROOT / "audio" / audio_obj.uid / audio_obj.audio_file
settings.CLIENT_MEDIA_ROOT / "audio" / audio_obj.uid / audio_obj.audio_file
)
# check if the file exists locally
if not local_file.exists():
Expand All @@ -301,7 +301,7 @@ def client_audio(request, audio_id):
return response

audio_file = (
settings.CLIENT_MEDIA_ROOT / "audio" / audio_obj.uid / audio_obj.audio_file
settings.CLIENT_MEDIA_ROOT / "audio" / audio_obj.uid / audio_obj.audio_file
)
with open(audio_file, "rb") as f:
response = HttpResponse(f.read(), content_type="audio/mpeg")
Expand All @@ -316,13 +316,13 @@ def ai_audio(request, audio_id):
return HttpResponse("No audio data found.", content_type="text/plain")

if (settings.STORAGE_SOLUTION == settings.STORAGE_SOLUTION_S3) or (
settings.STORAGE_SOLUTION == settings.STORAGE_SOLUTION_API
settings.STORAGE_SOLUTION == settings.STORAGE_SOLUTION_API
):
# we will grab it from the s3 and return it
s3_client = settings.BOTO3_SESSION.client("s3")
s3_key = f"Responder/tts/{res_audio_obj.text2speech_file.split('/')[-1]}"
local_file = (
settings.AI_MEDIA_ROOT / res_audio_obj.text2speech_file.split("/")[-1]
settings.AI_MEDIA_ROOT / res_audio_obj.text2speech_file.split("/")[-1]
)
# check if the file exists locally
if not local_file.exists():
Expand Down Expand Up @@ -378,11 +378,11 @@ def client_video(request, conversation_id):
video_paths = []
for video in videos:
video_path = (
settings.CLIENT_MEDIA_ROOT / "videos" / video.uid / video.video_file
settings.CLIENT_MEDIA_ROOT / "videos" / video.uid / video.video_file
)
if not video_path.exists() and (
settings.STORAGE_SOLUTION == settings.STORAGE_SOLUTION_S3
or settings.STORAGE_SOLUTION == settings.STORAGE_SOLUTION_API
settings.STORAGE_SOLUTION == settings.STORAGE_SOLUTION_S3
or settings.STORAGE_SOLUTION == settings.STORAGE_SOLUTION_API
):
video_path.parent.mkdir(parents=True, exist_ok=True)
s3_client = settings.BOTO3_SESSION.client("s3")
Expand All @@ -396,16 +396,11 @@ def client_video(request, conversation_id):
except Exception as e:
logger.error(e)
# response with the HttpResponse
response = HttpResponse(
str(e),
content_type="text/plain",
status=status.HTTP_500_INTERNAL_SERVER_ERROR,
)
return
continue
video_paths.append(video_path.as_posix())

output_path = (
settings.CLIENT_MEDIA_ROOT / "conversations" / f"{conversation.id}.mp4"
settings.CLIENT_MEDIA_ROOT / "conversations" / f"{conversation.id}.mp4"
)
output_path.parent.mkdir(parents=True, exist_ok=True)

Expand Down

0 comments on commit 6bb1ef3

Please sign in to comment.