0

I'm doing a project that requires the user to type in the phonetic sounds.

For example, th. Then the program will play a wave file that produce th sound. As there are many different wave files for a phonetic sounds, I have decided to group them into separate files, which means it would not be in the same folder of the .exe directory. In this case how do I play the sound that is from another file?

Here is the segment that I thought could work but it didnt.. Please help me!

FILENAME1 = strcat(text_data, ".wav");
FILENAME2 = strcat("wav" ,FILENAME1);
printf ("%s", FILENAME2);
PlaySound(TEXT(FILENAME2), NULL, SND_SYNC);

The text_data contains what the user types.such as "th". and the applicaiton plays the th.wav file Is it possible to play it from another folder? So that I can group various wav files into categories.

Then it will be something like this:;

Debug (contains the .exe file) --> consonants --> th.wav (this is the one I want to play but it will not be in the same directory as the .exe file.

Please help me. Thanks a lot!

Abhilasha
  • 929
  • 1
  • 17
  • 37

1 Answers1

0

You will need to give the complete path. For instance, if the files are in Debug\Sounds\SomeSound.wav, you will have to provide Sounds\SomeSound.wav as path.

Edit: You can use '+' operator to concatenate multiple strings. It should look like:

"Folder_Name\\" + text_data + ".wav"

You can also take a look at std::stringstream to do this job.

danish
  • 5,550
  • 2
  • 25
  • 28
  • hmmm, how do you include the complete path in the code? i do not know how to include them in the code above. – Kenneth Goh Jul 20 '12 at 05:23
  • Instead of just adding ".wav" to text_data, you need to add directory name as well before the text. – danish Jul 20 '12 at 05:33
  • do you mean something like this? FILENAME1 = strcat(\Debug\Sounds\,text_data, ".wav"); pls pardon me because i just started out learning programming thanks! – Kenneth Goh Jul 20 '12 at 05:50
  • FILENAME1 = strcat(text_data, ".wav"); FILENAME2 = strcat("consonants\\" ,FILENAME1); printf ("%s", FILENAME2); PlaySound(TEXT(FILENAME2), NULL, SND_SYNC); I tried doing it this way. but when i run the .exe file, it says there is error though i can compile it. is the code above correct? – Kenneth Goh Jul 20 '12 at 06:36
  • it is a pop up window that says that my program has stopped working and windows is checking for solution. – Kenneth Goh Jul 20 '12 at 07:18
  • when i put this only, FILENAME1 = strcat(text_data, ".wav"); printf ("%s", FILENAME1); it works well – Kenneth Goh Jul 20 '12 at 07:19