Home arrow Enthusiast Projects arrow 914 Media Server
914 Media Server
Thursday, 28 June 2007

This is an Enthusiast Project from James - 914pcbots.com Admin.

Since White Box Robotics released their 914 .NET controls, I've been tinkering around a little in C#. I've mainly programmed in Python before, although I did a little ANSI C in my college and university days, so C# .NET turned out not to be all that bad after all. I've been using C# .NET 2005 Express which is free from Microsoft.

I was thinking more about visual displays for the 914 since WBR have offered drive bay mounted 4" VGA screens for sale. I wanted to make best use of a small screen mounted on the 914 rather than having it constantly display the Windows desktop. As the majority of my 914 related programming will still likely be in Python, I also wanted to make any software I wrote be accessible from other languages through some sort of API, so I wrote this project - the '914 Media Server'.

The project is built around a sockets server, which I mainly got the code for from this tutorial. This allows commands to be sent over the network, or from the same machine - and for sound, speech or images to be played and displayed on the Bot. The application uses Microsoft Speech for the speaking, so you may need to install the SAPI 5 SDK in order to make it work. I've included the source code for this project as well as compiled executables that you can just use as they are if you wish. The download can be found here: MediaServerV1.zip (1.47Mb).

I've also included some sample sounds and some graphics of a face pulling various different expressions which I intend to display on my drive bay monitor. To use the ready compiled versions of the application do the following:

Download and Unzip the MediaServer.zip file. You'll notice that there's a folder in there called 'Executables' with a sub folder for the Server, and also a simple Client so you can try it out.

You can run both Client and Server on the same PC, or you can copy either Client and Server folders to PCs connected over a network.

Launch the '914 Media.exe' file - you'll notice it has two tabs, one labelled 'Data and sound', the other labelled 'Avatar and Images'. The Avatar tab has a picture of a man's head on it.

Go back to the 'Data and Sound tab', at the top you'll notice a port setting and a 'Start Listening' button. Set the port (the default is 8221) and click Start Listening - you should see it change to white and now it says 'Listening'.

Now launch 'Media_Client.exe' from the other folder. This also has a port and an IP setting. If you are running both client and server on the same machine leave the IP address as (this is localhost), if the Server is elsewhere then enter the IP address for the PC it is running on. Click 'Connect' - this should change to say 'Connected' if it is successful. You will also see that the 'Listening' button on the Server now also says 'Connected' too.

At this point you can flip the Server tab back over to the 'Avatar and Images' tab to see the mans face. As you click on the 'Imagexx' buttons on the Client you will see his expression change.

The four sounds I have included can also be played by clicking on the buttons labelled 'Sound01/02/03/04'. And now for the clever bit...

As you click on the buttons, you will notice that the file name of the image or sound is displayed in the long text box next to the blue 'Transmit' button. You can type anything in here to play or display other pictures or sounds provided they are either .jpg or .wav files and they exist in the 'Media Server\sounds' or 'Media Server\images' sub folders at the Server end. Just type in the file name and click 'Transmit' - if the name is invalid then it just won't do anything.

You can also make the Server speak using your default MS Speech voice. Just type in the phrase you which to speak and put a $ symbol on the end - the server will remove the $ and say everything that comes before. You can also keep sending multiple phrases with no $, then send the $ on it's own and it will say them all at once. If you wish to clear the buffer of everything sent before sending the $, then send a # symbol. The # will also help you clear everything if you make a typo.

You may wish to inspect the 'Data and sounds' tab of the Server as you are sending data - you will see data gets stored in various fields as it arrives. You may also type into these fields manually and click the buttons to speak/play sounds if you wish.

Obviously this is fun for a short while, but of limited use as it is. Note that the client application is really only there for demonstration. I intend to make this application part of my PPCBPAIFP project so that I may convey emotions from the 'AI' program that I end up writing, to Windows based Bots. I will also be doing something similar with the 914 specific .NET controls to read sensor data and actually drive the Bot about from my Python based application.

Feel free to use/modify the source for this application and use it in your own projects if you wish. To command the server from your own code, just attach to the socket and send a string containing the filename of the sound or image, or the text to speak followed by a $ symbol.

Discuss this article on the forums. (4 posts)

< Prev   Next >