Text to speech PROCESSING example for OSX

If you’re on OSX, you have access to a text to speech command named say.  This command typically lives at /usr/bin/say and it lets you read text using a robot voice.  If you’re unfamiliar with say, open up Terminal and type the following:
“say you are the master”
Image
Assuming your speakers aren’t muted, you should here a robot voice say “you are my master”.  The OSX say command has many voices built in which you can see by running this command:
“say -v ?”
And now for the magic.  Say you want your Processing sketch to speak.  No problem, here’s the source code to a simple sample of how to do this.
// Begin Processing Sketch
void setup() {
  size(200, 200);
  text(“Turn up your sound”, 5, 100);
  text(“and then click me”, 5, 120);
}
void draw() {
  // draw() must be present for mousePressed() to work
}
void mousePressed() {
String[] cmd = { “/usr/bin/say”, “What’s shaking bacon?” };
exec(cmd);
println(“mousePressed “);
}

// end sketch

Advertisements

Read flashlog.txt using AIR2 and NativeProcess

I’m sure you know by now that the Flash Platform is a great choice for making great front end applications to databases, or web services.  However, did you know with the release of AIR2 you can now use Flash or Flex to make gui front ends for existing programs or processes on your machine?  That’s right, AIR2 brings us a new feature called NativeProcess which let’s you communicate with existing programs or processes running on your machine.

Native Processes: Launch and communicate with native “out-of-band” processes. Bundle your own native executables, or call executables that you know are already on the machine. This feature requires that your application be installed with a native installer rather than though a .AIR file (we provide tools for building native installers).

  • Types of installers:
    • OS X: DMG
    • Windows: EXE
    • Linux: Debian and Red Hat Package Manager

See Christian Cantrell’s blog for the rest of the AIR2 new feature list.

I really enjoy building small apps for myself that are either fun or help with workflow.  Recently I was on an HTML5 project that required me to upgrade all my browsers to the absolute latest versions.  Well when I upgraded Firefox to 3.6, I could no longer use my Flash Tracer add-on, which caused a big workflow issue with my current Flex project.  While I know there are plenty of debug alternatives to Flash Tracer, I thought this would be a perfect chance to take AIR2’s NativeProcess out for a spin.  It also gave me a simple demo app for my talk at 360Flex about AIR.

So here’s what the simple logger app looks like.

AIR2's NativeProcess allowed me to build a simple flashlog.txt readerWith AIR2’s NativeProcess, you can build all sorts of cool new AIR apps like a flashlog.txt reader

Now that you’ve been blown away by my design skills, let’s walk through what, how, and where to get this app.

WHAT

AIR2, cross platform ( mac, win ), flashlog.txt reader.

HOW

Cross Platform – to take advantage of NativeProcess, your application must be installed as a native installer.  After you build your application, when you export the release build you select native installer instead of .air file.  When building AIR apps that you want to export as a native installer, you must build your application on the correct platform.  That is, I can’t build the .exe of this application on OS X, only the .dmg installer.

If using NativeProcess, export native installer instead of .AIR

FlashBuilder option for native installer is in export release dialog

Since this app is so small I had no problem storing the OS X and Windows specific code in the same place.  When the app is run I use flash.system.Capabilities.os to determine Windows or MAC.  I know the path to flashlog.txt is now hard coded into Flash Player, but I still have to build the platform appropriate path to flashlog.txt.

MAC – /Users/{username}/Library/Preferences/Macromedia/Flash Player/Logs/flashlog.txt

WIN – C:Users{username}AppDataRoamingMacromediaFlash PlayerLogsflashlog.txt

To grab the current username I parsed the results of File.userDirectory.url.  The last piece to setup is the path to the executable used by NativeProcess.  On OS X I’m using tail, which lives at /usr/bin/tail.  For Windows7, Powershell should live at C:WindowsSystem32WindowsPowerShellv1.0powershell.exe.

TIP : On OS X, you can use the “which” command to locate a program ( EX : which tail ).  On Windows, use the “where” command to locate a program ( EX : where powershell.exe ).  You will want to know this if the paths in this app doesn’t work for you.

Read flashlog.txt – to read flashlog.txt on OS X I’m using NativeProcess + tail.  On windows I’m using NativeProcess + Powershell’s Get-Content cmdlet.  Now that we know platform and paths, it’s time to setup our NativeProcessStartupInfo which will contain the executable we’re going to use, plus any required arguments.  In order to setup your NativeProcessStartupInfo object, you will need to know how to use the nativeprocess via command line first.  Using OS X’s tail as the sample, you can read the contents of flashlog.txt by running this in Terminal.

tail -f /Users/{username}/Library/Preferences/Macromedia/Flash Player/Logs/flashlog.txt
tail -f shows you the contents of a file as it changes

I can run tail in Terminal, or in an AIR application using NativeProcess

Here is the equivalent AS3 setup for running the same command via NativeProcess.  The executable is set to a File which points at tail.  The arguments required by tail are stored in a Vector<String>.

[as3]
var nativeProcessStartupInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo();
nativeProcessStartupInfo.executable = new File(&quot;/usr/bin/tail&quot;);

var processArgs:Vector.&lt;String&gt; processArgs = new Vector.&lt;String&gt;();
processArgs.push(&quot;-f&quot;);
processArgs.push( &quot;/Users/&quot;+user+&quot;/Library/Preferences/Macromedia/Flash Player/Logs/flashlog.txt&quot; );

nativeProcessStartupInfo.arguments = processArgs;
[/as3]

Now that the startup info is set, it’s time to setup our NativeProcess listeners, then start the process.

[as3]
var process:NativeProcess = new NativeProcess();

// add listeners
process.addEventListener(NativeProcessExitEvent.EXIT, onNativeProcessExit );
process.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, onStandardOutput );
process.addEventListener(ProgressEvent.STANDARD_INPUT_PROGRESS, onStandardInput );
process.addEventListener(IOErrorEvent.STANDARD_ERROR_IO_ERROR, onIOError );
process.addEventListener(IOErrorEvent.IO_ERROR, onIOError );

process.start(nativeProcessStartupInfo);
[/as3]

And that’s all there is to it, the important bits of reading flashlog.txt using AIR2’s NativeProcess.  NativeProcess has me excited because it opens a whole new world of apps that can be built.

I wrote this app for personal use and my 360Flex talk.  If you have interest in seeing more AIR2 samples, have a look at http://www.delicious.com/ericfickes/360FlexDCLinks+air2.  I put together a bunch of links supporting my talk on HTML and AIR which should keep you busy for a while.

WHERE

Contents of AIR2BUGGER_src.zip

Click me to download the full source AIR2BUGGER

OS X DMG INSTALLER WINDOWS EXE INSTALLER

It’s official, The Flash Platform rocks!

* UPDATE : all the videos were originally made and hosted at http://screentoaster.com which is now defunct.  I will get these videos updated someday.  Sorry for the loss.

In case you missed the June RMAUG meeting, my band The Compilers played our first hybrid concert and presentation show. Who are The Compilers? As far as I know, we’re Denver CO’s only Tech Funk Fusion trio that use internet technology along with analog instruments. By day we’re internet programmers, and by night we’re rockers. Right now majority of our software revolves around the Flash Platform, so it was only natural that we play at RMAUG.

Below is a recap of our setlist, and notes about the technology we presented on. When you see mentions of a Flash movie, these are not run as standalone SWF files. They are actually played by our Flex based Compilers Live Player. This application runs on our guitarist Jun Heider’s laptop, and the entire app is controlled over MIDI, via a Behringer FCB1010 Foot Controller, MMJ, and MERAPI.

Intro Song

For the first song of our set we decided to use a funny and informative Flash movie to give the audience a hint at what they’re about to see. For the June RMAUG show, this movie was updated to include spoken thank you slides for the companies that make our technology, and special shout outs to all the people who help us put on a great show.

Watch Flash Intro Movie

I want an iPhone

For our iPhone song we have another entertaining Flash movie that gets played during my iPhone solo part. Both this song, and the Flash movie where updated a bit for RMAUG. Unfortunately Soundbooth crashed on us when saving the recording of our live set, so I can’t play a clip for the remixed iPhone song, but you can watch the updated iPhone Flash movie.

Watch Flash iPhone Movie

All your base, are belong to us

This song is pretty straight forward when it comes to technology. We have a backing Flash movie that plays scenes from the ZeroWing video game, as well as the ‘All Your Base’ iPhone app for ZeroWing audio samples. I’m not including anything for this song besides, if you’ve seen us play before, this song now has a reggae feel to it. Prior to this show, ‘All Your Base’ was a hard driving all your punk are belong to us.

Sleep Tick

This is one of our original rock tunes which has been given a minor touch of technology. There is a middle part that I now break out into an iPhone solo, and we also have an AIR 2 powered audio visualizer. This particular app is one of the most exciting for me because I’ve been waiting for the day when we can use getMicrophone to pull raw data. Instead of explaining this one, you can watch it instead.

Tweet Jam v2

I’m happy to report our crown jewel of internet technology and audience interaction mashup “Tweet Jam”, has reached version 2. Both the song and the application have been rewritten especially for the RMAUG show. TweetJam is an instrumental jam song where the audience tweets at @thecompilers during our show, then our Roboreader application imports the @mentions and reads them back to the crowd via robot voice. Since our application reads the live Twitter feed, you don’t have to be at our shows to participate! A final point of interest for this application is that I run this on my laptop and control it using a wired XBOX 360 controller. There’s not much more to explain, but there is a video showing it in action.

http://www.screentoaster.com/swf/STPlayer.swf

James vs. Rick

Our final song of the night uses two applications. One is a game for the audience, and the other is a simple audio app. The game is an AIR application that connects to the ‘phone game company’ MegaPhone service and displays a specially assigned 888 telephone number, and a range of numbers to press in order to vote for James Brown ( 0 – 4 ) or Rick James ( 5 – 9 ). When a player calls in and presses a number from a specific range, our AIR app will play an appropriate audio sample while we’re playing. Our AIR app keeps track and displays the running vote count, then at the end of the song we fade and play a funny video from the winner.
The second application ‘Funky Funky’ is a simple AIR2 application that uses NativeProcess to say “Funky Funky”. While this doesn’t sound like anything noteworthy, it’s a perfect application for this particular jam because OSX’s SAY command has a voice called “Bells” that speaks in a melody that matches the song we’re playing. Of course this doesn’t make much sense not knowing what the song sounds like, so here’s the actual application for you download and try out. Note, this is an AIR2 app that uses NativeProcess, so this is an OSX only application.
Funky Funky! A text to speech OSX application by The Compilers
For your entertainment, here are two funny videos from James Brown and Rick James.

The Flash Platform Rocks!

So there you go, proof that the Flash Platform rocks! I haven’t thought of any rocking ending other than, go check out AIR2. The Flash Platform is no longer restricted to the browser. Let all the HTML heads keep the browser, I want to rock on stage with Flash.

Photos

We didn’t get a recording of the show, but we do have a photo album of the June RMAUG on Facebook.

The Compilers Next Show

If you missed The Compilers at RMAUG, we are playing at Ignite Denver 7 on July 27th. If you can’t make that show, be sure to at least tweet @thecompilers on July 27th to get yourself heard.
Be sure to check out The Compilers World for information from the future of the internet rock trenches.

How to make your Adium icon fiery

Here’s a fun tip on creating a fiery looking buddy icon in Adium for OSX.

  1. Take picture in Photo Booth, or directly from Adium’s ImagePicker
  2. Click spiral effect button, then choose the Color Invert filter
  3. Click Set to apply filter
  4. Click your buddy icon, click Choose Icon
  5. Repeat steps 2 – 4 and apply the filters False Color, then Concert
  6. Voila – your buddy icon is red hot!

Typically I’ll take my photos using Photo Booth so I can keep the original, and sometimes I may even use that picture for my dailymugshot.  When you walk through these filters, you’ll notice some filters won’t work as well for some photos, so play around with what you use.  Sometimes I’ll replace Color Invert with X-Ray, or Concert with Gamma Adjust.  It all depends on the picture I choose for a buddy icon.  Sometimes I’ll just keep layering until I create some crazy looking buddy icon, go crazy!

Here’s a photo step by step so you can see the final product.

1.The Original

Starting picture

2.Color Invert

Color Invert filter

3.False Color

False Color filter

4.Concert

Concert filter

A volume failed to mount (Error code -6602)

Yesterday morning I started work as usual as ran into a problem mounting one of the shares from my XP PRO machine on my Macbook Pro.  Obviously the first question I asked was WTF? Everything worked yesterday, and not today.

I did some Googling and found mention about opening some UDP ports, but my TCP/IP settings currently has all ports open, so that didn’t help.  Then just for giggles I decided to turn off simple file sharing.  That fixed it!

So if you receive the message “A volume failed to mount”, and then another one with “Error code -6602” in it, you should check your PC’s file sharing settings.  You would do this by following these steps.

How to disable simple file sharing on XP

  1. Open Windows Explorer ( Win+E  or  double click My Computer )
  2. Click Tools > Folder Options
  3. Click the View Tab
  4. Scroll down to the bottom, and uncheck “Use simple file sharing (Recommended)”
  5. Then retry mounting the share on OSX

OSX FlexBuilder Java Heap Space error

Here’s an error I’ve run into from time to time while programming Flex on OSX

	[compc] Error: Java heap space
	[compc] java.lang.OutOfMemoryError: Java heap space	

This error was a real pain in the arse. I found a lot of people having similar issues and they all fixed this problem by setting ANT_OPTS as an environment variable to increase the memory size. This didn’t work for me. I set ANT_OPTS in my .profile, as well as in .MacOSX/environment.plist.  No luck.  I never figured out why the environment variable route didn’t work, but I was able to fix this error within Eclipse.

If you run into this error while running Ant build scripts, try the following steps.

  1. Run Menu > External Tools > Open External Tools Dialog…
  2. Select your Ant build file on the left
  3. Click the JRE tab on the right
  4. Enter “-Xmx640m” in the VM arguments field ( without quotes )
  5. Click Apply, then Run
Flex JVM preferences

Flex JRE preferences

Hopefully this will get you going.

Handy OSX developer tools

This year I had the challenge of using a MacBook Pro as my work machine. While figuring out how to work on the shiny toy, I found a few apps that are worth using. If you’re an apple genius, or end up having to use OSX, I highly recommend getting these apps.

Adium X – OSX Multi server chat client – www.adiumx.com

AppZapper – OSX Uninstaller – www.appzapper.com

BBEdit – OSX Text editor and more – www.barebones.com

Dreamweaver CS3www.adobe.com/products/dreamweaver/

Flash CS3 – *Don’t even bother with flash 8 on OSX – www.adobe.com/products/flash/

Photoshop CS3www.adobe.com/products/photoshop/

Guiffy – OSX Diff Tool – www.guiffy.com

MacParDeluxe – OSX Binary group util – www.xs4all.nl/~gp/MacPAR_deLuxe/

Parallels – OSX Virtual PC – www.parallels.com

Quinn – OSX Tetris clone – simonhaertel.de/quinn

SmartSVN – OSX SVN GUI Client – www.syntevo.com/smartsvn/

Soap Client – OSX SOAP Development tool – http://scan.dalo.us/

Speed Download – OSX Download Manager – www.yazsoft.com

Split And Concat – OSX Binary group utility – www.xs4all.nl/~loekjehe/Split&Concat/

Synergy – OSX iTunes controller – wincent.com/a/products/synergy-classic/

Toast Titanium – OSX DVD / CD Burning App – www.roxio.com

Transmission – OSX BitTorrent client – http://transmission.m0k.org/

Transmit – OSX FTP Client – www.panic.com/transmit/

VLC Player – Great OSX video player – www.videolan.org/vlc/

What Size – OSX Disk utility – www.id-design.com/software/whatsize/

Witch – OSX Alt Tab utility – www.manytricks.com/witch/