[PYTHON] [Voice analysis] Collect bird song data with xeno-canto

What is xeno-canto?

Bird bark database. There is API that can be handled by json. This time, I used Python to collect all the calls of the genus Fulica (Coots) in Japan.

Source code

import requests
import json
import urllib

url = "https://www.xeno-canto.org/api/2/recordings?query=gen:Fulica+cnt:japan" 

#get json(requests.get)

response = requests.get(url)
jsonData = response.json()["recordings"]

#Download section(The file name is{id}.mp3)

for data in jsonData:
    url = ("http:"+data["file"]) 
    title = data["id"]
    urllib.request.urlretrieve(url,"{0}.mp3".format(title))

About url

According to the Xeno-canto API documentation, the query is

Of this time

url = "https://www.xeno-canto.org/api/2/recordings?query=gen:Fulica+cnt:japan" 

Then, it is specified by gen: Fulica, cut: Japan.

About the download section

url = ("http:"+data["file"])

In, the download url is in the key [" file "]. (Since http: is not attached, add it.)

environment

python 3.7.4 (Anaconda) MacOS Catalina 10.15.5

Recommended Posts

[Voice analysis] Collect bird song data with xeno-canto
Voice analysis with python
Voice analysis with python
Data analysis with Python
Collect anime song lyrics with Scrapy
Data analysis starting with python (data visualization 1)
Data analysis starting with python (data visualization 2)
I tried factor analysis with Titanic data!
[Voice analysis] Find Cross Similarity with Librosa
Data analysis starting with python (data preprocessing-machine learning)
Data analysis for improving POG 2 ~ Analysis with jupyter notebook ~
[Introduction to minimize] Data analysis with SEIR model ♬
Data analysis Titanic 2
Data analysis python
Data analysis Titanic 1
Data analysis Titanic 3
[Linux command] Petit data analysis with grep / awk / sort command
Data analysis for improving POG 1 ~ Web scraping with Python ~
Reading Note: An Introduction to Data Analysis with Python
Data analysis environment construction with Python (IPython notebook + Pandas)
Challenge principal component analysis of text data with Python