text to speech converter

hi guyss,
i am trying to make such an device which will convert given text input by serial monitor will be converted into
corresponding voice signal. i am using micro sd card for different voice signals for different text inputs.
i have written a piece of code this , have a watch and tell me how should i modify this as output of this code is not desirable

#include <SD.h> // need to include the SD library
//#define SD_ChipSelectPin 53 //example uses hardware SS pin 53 on Mega2560
#define SD_ChipSelectPin 4 //using digital pin 4 on arduino nano 328, can use other pins
#include <TMRpcm.h> // also need to include this library…
#include <SPI.h>

char receivedChar;
boolean newData = false;

TMRpcm tmrpcm; // create an object for use in this sketch

void setup(){

tmrpcm.speakerPin = 9; //5,6,11 or 46 on Mega, 9 on Uno, Nano, etc

if (!SD.begin(SD_ChipSelectPin)) { // see if the card is present and can be initialized:
Serial.println(“SD fail”);
return; // don’t do anything more if not
tmrpcm.play(“hello.wav”); //the sound file “music” will play each time the arduino powers up, or is reset

void recvOneChar() {
if (Serial.available() > 0) {
receivedChar = Serial.read();
newData = true;

void showNewData() {
if (newData == true) {
Serial.print("This just in … ");
newData = false;
void loop(){

if(Serial.read() == receivedChar){ //send the letter p over the serial monitor to start playback


Read the “how to use the forum” post and post your code within the code tags </>

sucharita: tell me how should i modify this as output of this code is not desirable

Perhaps if you told us what aspect of the output is not desirable... From a quick look it appears that each time through loop() if there are two matching characters in the serial buffer it plays the file named "receivedChar". Not the file named the same as the received character, just the same "receivedChar" file, over and over. That sounds undesirable. Usually when one talks about "text to speech", one means "speaking text like a human would", not "reading the input character by character."