In one of the recent workshops held at YDIT college of engineering located in Bangalore, we demonstrated the capabilities of using arduino as well as processing to accomplish various simple applications. One of the student was interested in knowing how an arduino could help accomplish a text to speech conversion. Due to shortage of time we were not able to demo the same to student.
Here is short write up on how to accomplish the same.
We decided to output a string from arduino which inturn basically read the resistance of a potentiometer and passed the same data using the serial port of the Arduino.
Here is how it works
Here is the code for the Arduino
int sensorPin = 0; // select the input pin for the potentiometer
int sensorValue = 0; // variable to store the value coming from the sensor
void setup() {
Serial.begin(9600);
}
void loop() {
// read the value from the sensor:
sensorValue = analogRead(sensorPin);
// Send through serial
Serial.println(sensorValue);
// wait 1000 milliseconds before the next loop
delay(1000);
}
And from the processing end we used a library from Nikolaus Gradwohl
http://www.local-guru.net/blog/pages/ttslib
Here is how the processing code is organized
import processing.serial.*;
import guru.ttslib.*;
TTS tts;// Create object from TTS class
Serial myPort; // Create object from Serial class
String inString; // Data received from the serial port
int inByte;
void setup() {
size(200,200);
tts = new TTS();
println(Serial.list());
String portName = Serial.list()[0];
myPort = new Serial(this, portName, 9600);
}
void draw() {
if ( myPort.available() > 0) { // If data is available,
inString = myPort.readStringUntil('n');
}
println(inString);
if (inString != null) {
// trim off any whitespace:
inString = trim(inString);
// convert to an int
inByte = int(inString);
}
background(255); // Set background to white
if (inString != null)
{
tts.speak(inString);
tts.speak("ohm");
}
if (inByte == 0) { // If the serial value is 0,
fill(0); // set fill to black
}
else { // If the serial value is not 0,
fill(inByte/4); // set fill to light gray
}
rect(50, 50, 100, 100);
}