I've got issues: files are null

41 views
Skip to first unread message

NIA yulma

unread,
Apr 16, 2024, 8:51:47 AMApr 16
to Freesound API

hello, there. thank you for keeping this good platform.

I tried to use API and download sound files. but it doesn't work.
is there a limitation to use?

I use colab at the moment. the belowed error message happened again and again:


[My CODE in COLAB]
import requests
import os

# Function to download audio files
def download_audio(url, file_path):
response = requests.get(url)
if response.status_code == 200:
with open(file_path, "wb") as f:
f.write(response.content)
print(f"Downloaded: {file_path}")
else:
print(f"Failed to download: {file_path}")

# Define your API key
api_key = "h187YsuQuF1mjAGmteSy8pJLIQOC2Qm79ZZ25eea"

# Example: Search for sounds related to "dog"
search_query = "rain"

# Construct the URL for the search endpoint
base_url = "https://freesound.org/apiv2/"
search_url = f"{base_url}search/text/?query={search_query}&token={api_key}"

# Send the GET request to the API
response = requests.get(search_url)

# Check if the request was successful
if response.status_code == 200:
# Parse the JSON response
data = response.json()

# Create a directory to store the audio files
os.makedirs("audio_files", exist_ok=True)

# Iterate over the results
for result in data["results"]:
# Get the URL of the audio file
audio_url = result["url"]

# Download the audio file
file_name = f"{result['id']}.ogg"
file_path = os.path.join("audio_files", file_name)
download_audio(audio_url, file_path)

# Store the file path in the DataFrame (optional)
result['file_path'] = file_path
else:
print("Error: Unable to fetch data from the API")

---------------------------------------------------------
but results:
Playing sound: Transformed wind chimes: Nature-Symphony 4
---------------------------------------------------------------------------
CalledProcessError Traceback (most recent call last)
<ipython-input-24-1e1299775242> in <cell line: 18>()
34 # Play the audio file
35 print(f"Playing sound: {sound_name}")
---> 36 playsound.playsound(audio_file_path)
37 else:
38 print("Error: Unable to fetch data from the API")

5 frames
/usr/lib/python3.10/subprocess.py in check_call(*popenargs, **kwargs)
367 if cmd is None:
368 cmd = popenargs[0]
--> 369 raise CalledProcessError(retcode, cmd)
370 return 0
371

CalledProcessError: Command '['/usr/bin/python3', '/usr/local/lib/python3.10/dist-packages/playsound.py', 'Transformed wind chimes: Nature-Symphony 4.wav']' returned non-zero exit status 1

--
https://freesound.org/people/NIA_forest/

Frederic Font Corbera

unread,
Apr 17, 2024, 7:00:10 AMApr 17
to freeso...@googlegroups.com
Hi,

You seem to be passing a wrong URL to the download function. You should get a preview URL to do a simple sound download, but you're passing the URL of the sound page. Also I'd recommend you using the freesound-python client (you can install in colab) as it should facilitate things. Also look at examples for downloading files. https://github.com/mtg/freesound-python

Cheers,

frederic

--
Frederic Font - ffont.github.io
Music Technology Group, UPF - mtg.upf.edu
Freesound - freesound.org



--

---
You received this message because you are subscribed to the Google Groups "Freesound API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to freesound-ap...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/freesound-api/41696cb6-dd90-4a22-a8d3-40e11b41f8b2n%40googlegroups.com.

NIA yulma

unread,
Apr 17, 2024, 8:41:15 AMApr 17
to Freesound API
lovely to hear the solution.
I'll try :) 

have good weds

NIA yulma

unread,
May 7, 2024, 5:40:05 AMMay 7
to Freesound API
hello, 
I'd tried example.py in terminal but it requires API key. 
it's 4th times but i couldn't figure it out.
thanks, nia

----code in terminal--

user@Userui-MacBookPro freesound-python-master % python3 examples.py

You need to set your API key as an environment variable

named FREESOUND_API_KEY

user@Userui-MacBookPro freesound-python-master % export FREESOUND_API_KEY=c7WXJg8yPjcLC8fg9f5pkUpmzcV5fQG97uBO6Hc9


user@Userui-MacBookPro freesound-python-master % python3 examples.py

You need to set your API key as an environment variable

named FREESOUND_API_KEY

user@Userui-MacBookPro freesound-python-master % 


On Wednesday, April 17, 2024 at 8:00:10 PM UTC+9 frederic wrote:

Frederic Font Corbera

unread,
May 13, 2024, 10:44:31 AMMay 13
to freeso...@googlegroups.com
Hi,

You need to obtain an API key from Freesound . You can get one at this URL: https://freesound.org/apiv2/apply

frederic

--
Frederic Font - ffont.github.io
Music Technology Group, UPF - mtg.upf.edu
Freesound - freesound.org


Reply all
Reply to author
Forward
0 new messages