1

I am trying to fetch .wav file from Amazon S3 and modify it using AudioSegment library. For fetching .wav file from S3, I have used boto3 and IO module. For Audio operations, I am using AudioSegment module.

When I fetch file from S3 using BytesIO and pass it to AudioSegment, I am getting "System can not find the file specified" error. Below is my code

import boto3
from pydub import AudioSegment
import io
client = boto3.client('s3')
obj = client.get_object(Bucket='<BucketName>', Key='<FileName>')
data = io.BytesIO(obj['Body'].read())
sound1 = AudioSegment.from_file(data)

I am getting error at AudioSegment.from_file(data)

System can not find the file specified

James Z
  • 12,209
  • 10
  • 24
  • 44
gans2910
  • 51
  • 2
  • Not familiar with any of this, but check your API docs. It looks like you are trying to pass a stream of bytes to something expecting an actual _file_ or even _filename_. These two things are not the same. –  Dec 19 '18 at 19:48
  • You're calling a method called `from_file` so I assume it expects `data` to contain a filename. It probably doesn't? – James Z Dec 19 '18 at 19:48
  • I referred this link - https://stackoverflow.com/questions/48997852/boto3-s3-object-parsing where jmkmay suggested above solution. – gans2910 Dec 20 '18 at 02:10

1 Answers1

0

Try specifying the format argument for AudioSegment. For example:

sound1 = AudioSegment.from_file(data, format='mp3')
evlit
  • 1