SoundCloud for Developers

Discover, connect and build

We use cookies for various purposes including analytics and personalized marketing. By continuing to use the service, you agree to our use of cookies as described in the Cookie Policy.

Backstage Blog July 12th, 2012 Announcements Events Hacks Recording and Sharing Phone Calls By Paul Osman

A few weeks ago, I attended News Hack Day in San Francisco. News Hack Days are events that bring together journalists, developers and designers for multi day creative coding and brainstorming sessions.

I really like the idea of hack days that bring together people from different backgrounds. After chatting with a few journalists, it became obvious to me that recording interviews on the phone is a real pain. I saw this as an opportunity to build a fun app that would make this easier for people.

I spent most of my time during the two hacking days building Phone Recorder. It's a simple node.js application that uses Twilio and SoundCloud to record conference calls and upload them to the user's SoundCloud account as either public or private sounds. You can give it a whirl here or check out the source code on GitHub. I demoed the application at the end of the event and got some really good feedback.

The idea is pretty simple. A user signs into the app using their SoundCloud account and creates a new call. They're given a number to call, and two sets of codes: one for the moderator and another for participants. When they call the number, they're prompted to enter a code. Once the call is finished (the moderator hangs up), the audio recording of the call is downloaded from Twilio and uploaded to the moderator's SoundCloud account.

One tricky bit was associating the moderator's SoundCloud account (and access token) with a specific call. I decided to use Redis for this. You could use any server-side data store, Redis is just nice and simple, which is great when you're at a hack day rushing to get something done.

Once that bit was solved, the code that uploads to SoundCloud was simple to write:

exports.postTrack = function(file, title, sharing, token, callback) {
  var stat = fs.statSync(file);
  var mime = 'application/octet-stream';

  var req = rest.post('https://api.soundcloud.com/me/tracks.json', {
    multipart: true,
    data: {
      'track[title]': title,
      'track[sharing]': sharing,
      'track[asset_data]': rest.file(file, null, stat.size, null, mime),
      'oauth_token': token
    }
  });

  return req.on('complete', function(data) {
    return callback(data);
  });
};

// download the audio recording from Twilio and post to SoundCloud
return util.downloadFile(recordingUrl, function(file) {
  var scope = call.private ? "private" : "public";
  return soundcloud.postTrack(path, title, scope, token, function(r) {
    return console.log("Posted: " + r.title);
  });
});

Attending the Hack Day was a good opportunity to build something useful that uses sound on the web in a new, interesting way.

Built an awesome hack using our API? Let me know about it in the comments.