in infra-as-code/modules/ingest-pipeline/cf-audio-redaction/audio_redaction.py [0:0]
def download_audio_from_gcs(self, src_bucket_name, audio_file_name):
"""Downloads an audio file from Google Cloud Storage to a temporary location.
Args:
bucket_id (str): Bucket name
filename (str): Blob name
Returns:
str: audio
"""
try:
bucket = self.storage_client.get_bucket(src_bucket_name)
blob = bucket.blob(audio_file_name)
tmp_audio_file = f"{audio_file_name.split("/")[1]}"
destination_file_name = f"/tmp/{tmp_audio_file}"
blob.download_to_filename(destination_file_name)
# 1. File size comparison
if os.path.isdir(f'/tmp/{tmp_audio_file}'):
print(f'Error: {f'/tmp/{tmp_audio_file}'} is a directory, not a file.')
else:
file_size = os.path.getsize(f'/tmp/{tmp_audio_file}')
print(f'File downloaded. Size: {file_size} bytes')
print('Downloaded audio from gcs')
return tmp_audio_file
except Exception as e:
print(f"Error uploading file: {e}")
return ''