Playing bird calls in Max

Using the xeno-canto API

Note: 2024/01/21 – patch not working in repository, but has been fixed locally with updates to birdcall4.maxpat.

(updated 1/25/2021)

This Max patch retrieves bird call data from the xeno-canto API, then plays an mp3 file of the bird call using the URL from the query.

If you’d like to modify this patch to play the sounds of other birds, you can get the species names from: http://www.xeno-canto.org

Click to hear the bird call from the patch:

download:

https://github.com/tkzic/internet-sensors

folder: bird-calls

files

Max
  • bird-call4.maxpat
  • nothing-detector.maxpat (for tracking progress of html request)

authorization

  • none required

instructions

  • Open the Max patch: bird-call4.maxpat
  • Select a bird from the menu. Wait a few seconds. If the hit-counter increases above zero then the search was successful.
  • Click the button to start audio.
  • Click the button to play a random recording from the query

notes

There are two html queries. The first query retrieves an array of recording records for a selected bird. The second query downloads the .mp3 file with the actual recording.

The patch uses [dict] and [maxurl] to format execute the first query. Then it uses [jit.uldl] to download the .mp3 file.

New York Times article search API

update 6/2014 – This version of the API appears to be broken. Will need to update the example below.

Note: As of June 1, 2014, version 1 of the Article Search API has been deprecated. Please use version 2.

original post

http://developer.nytimes.com/docs/article_search_api

Example that works (except for the api key):

http://api.nytimes.com/svc/search/v1/article?query=dubstep&begin_date=20121101&end_date=20121130&api-key=123

I loaded the result file from this query into a max patch: JSON_readwrite-nyt-test and printed out the title and body of the first article returned.

There are examples in the above link and explanation of using ‘facets’ which give you stuff like counts of articles and mentions of things like corporation names & other common things. Also some logic tricks for doing complex queries.

 

final notes on attempts to convert XML to JSON in Max

update: this conversion may be built into Max 6.1.7… [js]

For now I am using the following method:

  • Write xml using jit.textfile
  • use aka.shell to convert xml to json using python script xml2json.py (modified header)
  • read the json file in using method in JSON_Readwrite.maxhelp

Its not elegant but it works on the MAC – without installing additional software, like node.js and all of its packages.

update: 3 weeks later. Have been using the above method and also calling curl from aka.shell – writing XML files to /tmp – Then following steps 2 and 3 above. Works fine.

 

 

 

 

Max XML to JSON conversion

update 6/2014 – In the internet-sensors chatbot project, I am using a python script to convert xml to json: https://reactivemusic.net/?p=9834 – also the most recent version of Max 6.1.8 now includes JSON parsing in the javascript object

original post

notes:

Lest I completely forget. There is now an xml.parse object in max.

  • So I have figured out how to write xml files from an http request using jit.textfile
  • How to read an xml file into javascript
  • many ways of parsing xml in max using externals from sadam, jasch, and xml.parse – see weather report from mz
  • some – ways of converting xml to json using php (not quite), java, and node.js – but not yet in core javascript.

So the current approach is to try to find or write a javascript function to convert and xml string to a json object – or even to a json string. Or to find a generic xml/json converter which can be run in the background from the command line

 

Max XML to JSON

update 4/2014 – Max6.1.7 js object now incudes JSON parsing

notes

(update) none of these worked – the solution ended up being a patch from Peter Nyoeber explained elsewhere in this blog…

Looking for a solution to converting xml to json in max

https://gist.github.com/4153569

From this…

http://davidwalsh.name/convert-xml-json

From Stack Overflow – a simple function…

http://stackoverflow.com/questions/7769829/tool-javascript-to-convert-a-xml-string-to-json