Twitter search in Max

Here’s a basic pattern:

  1. Send search string to Twitter
  2. Get JSON result
  3. Parse result and do something with it.

From Max, there are many ways to do this:

searchtweet – mxj, twitter4j

by Gokce Kinayoglu

http://cycling74.com/toolbox/searchtweet-design-patches-that-respond-to-twitter-posts/

This patch demonstrates the Twitter search API. Its self contained within Max – using the [mxj search tweet] external. This object allows you to input

  •  keyword
  • maximum number of results

The response is:

  • username
  • Tweet text
  • date/time

This patch is a great way to get Tweets into Max. You can use a [metro] object to poll the API. There are no additional programs running outside of Max. 

The limitation is lack of flexibility. You don’t have access to any of the other parameters in the request response. For example, geographic data. Also, it can be difficult to install and maintain java [mxj] programs in Max.

Here’s a screenshot of a patch which takes the output of the above patch and sends it to the aka.speech object – which runs the Mac Os built in text-to-speech program

Speech to text in Max

Using the Google speech API

(updated locally 1/21/2024 – changed binary path to sox for homebrew /opt/homebrew/bin/sox in [p call-google-speech]

Also changed some of the UI and logic for manual writing and sending.

(updated 1/21/2021)

This project demonstrates the Google speech-API. It records speech in Max, process it using the Google API, and displays the result in a Max [message] object.

download

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

folder: google-speech

files

main patch
  • speech-to-google-text-api6.maxpat
abstractions and other files
  • JSON-google-speech.js (parses JSON response from Google API)
  • ms-counter.maxpat (manages audio recording buffer)

external Max objects

external programs

sox: sox audio conversion program must be in the computer’s executable file path, ie., /usr/bin – or you can rewrite the [sprintf] input to [aka.shell] with the actual path. In our case we installed sox using Macports. The executable path is /opt/local/bin/sox – which is built into a message object in the subpatcher [call-google-speech]

get sox from: http://sox.sourceforge.net

note: this conversion may not be necessary with recent updates to Max and the Google speech API

authorization

  • none required – so far
This may be changing.
Insert here: how to get a speech-api key from Google 

instructions

  • Open Max patch: speech-to-google-text-api6
  • Turn on audio
  • Press the spacebar. Start talking. Press the spacebar again when you are finished. The translation will begin automatically

Note: If you have a slow internet connection you may need to tweak the various delay times in  the [call google-speech] sub patch.

send Tweets using speech

Max [send] and [receive] objects pass data from this project to other projects that send Tweets from Max. Just run the patches at the same time.

Also, check out how this project is integrated into the Pandorabots chatbot API project

https://reactivemusic.net/?p=9834

Or anything else. The Google translation is amazingly accurate.

revision history

  • 4/24/2016: need to have explicit path to sox, in the call-google-speech subpatch. In my Macports version the path is /usr/local/opt/bin/sox.
  • 5/11/2014: The newest version requires Max 6.1.7 (for JSON parsing). Also have updated to Google Speech API v2.
  • update 3/26/2014 to use auto-record features developed for chatbot conversations

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.

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

Max bicycle speed / engine example patch

notes:

I’m trying to organize the examples for measuring wheel speed. These patches need to be consolidated – and have the extraneous stuff stripped out. For example, just need a wii-mote detector without all the envelope stuff.

max teaching examples/tz examples

bicycle2.maxpat – need to clean up

wheelspeed.maxpat

waveguide engine3c bike.maxpat

notes: wheelspeed2.maxpat has some experiments with smoothing by converting to signal in order to get more data points.