Home > database >  API custom voice downloading via Python
API custom voice downloading via Python

Time:08-10

Is there any way I can download an mp3 file using Python because as soon I get to this URL it automatically opens "file save dialog box" and I'm not able to download it using either the python requests module or PycURL programmatically? I'm getting this URL by using API. There is nothing much you can do with their API.

There are 5-6 files that I want to download with different names like 1st file with 1.mp3, 2nd file with 2.mp3, and so on. Is there any way I can do that? I know I'm missing something I just couldn't find what that is.

CodePudding user response:

            file = open(filepath, "wb")
            file.write(audiourl)
            file.close()

If you have an audio URL in your JSON response, you will get a file with the URL, not the content behind the URL

To get actual audio, you need to request the URL

 audio_response = requests.get(audiourl)
 if audio_response.status_code == 200:
     with open('someFileName.mp3', 'wb') as f:
         f.write(audio_response.content)
 else:
      # Do something if not correct
  • Related