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
--
---
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.
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 %
To view this discussion on the web, visit https://groups.google.com/d/msgid/freesound-api/35a3cf59-3411-4e11-80d0-347c893a0900n%40googlegroups.com.