This program will use DirectX for playing sound files. If you are working on this program in a lab other than the one our class is in, you may need to plug a set of headphones to hear.
The sound files (WAV files) will be used to make the computer say a number, rather than just printing the number to the screen. The process can be broken down into a series of functions. The functions are presented here step-by-step, so you can test each function and make sure it works before writing the next function.
You should write a main program to test your functions as you go. Use exactly what is shown below. The only thing you should change is the name of the function and the comments:
#include "GraphicsMagician.h"
// your function prototypes go here
int main()
{
Machine.Start();
int number;
do
{
cout << "Type a number:";
cin >> number;
YourTalkingFunction(number);
} while (number != 0);
return 0;
}
// your functions go here
This will let you type numbers and send them to your talking functions to test, until you type a zero.
The first function you should write should receive an integer from 1 to 9, and play the appropriate one of 9 WAV files. With the Graphics Machine, you can play a WAV file with one command:
Machine.PlayWave("numbers\\4.wav",2);
Give the path and name of the file (remember to use a double-backslash wherever you need a backslash). The second parameter, 2, tells the Machine to wait until the sound is done playing before continuing. This is important in this application, because we'll be playing a series of sounds in succession.
Here are the sound files you have to work with. They use the numerals as the filenames, except for the phoenetic sounds needed for "teens" and "tees". Each file had the extension ".wav":
0, 1, 2, 3, 4, 5, 6, 7, 8, 9 10, 11, 12, thir, fif, teen, ty, 20 100, 1000, 1000000, 1000000000
Note that by combining the sounds in the second row and those in the first, you can "say" all the numbers from 0 to 99. But you'll only need the first row for this first function.
Note also that some of the newer files are in other languages, which is why the filenames were changed from things like "two.wav" to "2.wav". There are text files along with the other languages explaining the logical differences, which so far only show up in Function 2.
Here are the voice files. Thank you to those who volunteered to be immortalized in this assignment!
andrew.zip | asun.zip | greg.zip | jimmy.zip | jody.zip | karen.zip | nick.zip | penny.zip | tina.zip
The second function is probably the hardest. This function should receive a number from 1 to 99 and say it correctly. With the exception of the numbers from 11 to 19, you can use function #1 for saying the one's digit. (For example, for the number 43, you have to say "four-ty" and "three". The "three" can be handled by function #1.
For the ten's digit, 40, 60, 70, 80, and 90 can be said by just saying the number with a "ty" after it. 30 and 50 are special cases, using the sounds "thir" and "fif". 10 and 20 each have a complete sound.
For the values 1 to 9, and 21 to 99, all you have to do is say the ten's value followed by the one's digit. Use your function #1 for the one's digit. 11 and 12 have their own sounds. 13 to 19 work just like 30 through 90, but the "ty" sound is replaced with "teen".
Remember, you can use integer division and mod operator (%) to split the digits. For example, if n is a number from 1 to 99, you can separate the ten's digit and one's digit as follows:
tens = n / 10;
ones = n % 10;
Now things get a lot easier. This function should receive a number from 1 to 999 and say it correctly. If the number is less than 100, just call function #2. If the number is 100 or greater, split off the hundreds digit and send it to function #1, then say "hundred". Then send what's left to function #2!
This last function receives an unsigned long integer from 0 to just over 4 billion and says it correctly! But all you need is to use function #3 over and over. Find how many billions there are (integer division by 1 billion), and if it's more than zero, call function #3, then say "billion". Then find out how many millions there are, and if it isn't zero, call function #3 then say "million". Do the same thing again for the thousands. And finally call function #3 one last time for whatever's left less than 1000.
The only special case in this function is zero!
To do this, you'll have to find one of the voices that has a file named "negative.wav". Not all voices have this file included.
Add one more (even better!) function that says any positive or negative integer in the range +/- 999 billion. (Although long integers will only go from +/- 2 billion.)
Write a function that receives a floating point number in the range 0 to one less than 1 trillion (999,999,999,999). Send a second parameter that tells how many decimal places you want the computer to say. There's one more WAV file for this part: "point.wav".
For each digit after the decimal point, just read its value from 0 to 9. For example, 31,457.623 should be said as "thir-ty-one-thousand-four-hundred-fif-ty-seven-point-six-two-three".
The program to say the above would contain instructions like the following:
double d = 31457.62314; // added extra digits to demonstrate
SayDouble(d,3); // the '3' means "only say the first 3 decimal places"
This additional function should use your best integer function above to say the integral part of the number.
(If you do this, turn this in along with your best version above.)
Write a main program that will ask the user for the largest random number to pick in the range 5 to 30,000. Use the random number generator to select a number in the chosen range. For example, if I type "100", it should choose random number from 1 to 100. You can use the following instruction:
RandomNumber = rand() % limit + 1; // select a number from 1 to limit
In a loop, ask the user to guess the random number. Tell the user if their guess is "too high", "too low", or "correct!" Only exit the loop if their guess was correct. They should keep guessing until they get it right.
Your program should say each number that the user guesses. You can print "too high", "too low", or some exciting "you got it right!" message to the screen, or you can record WAV files so the computer says the response. (Such as "for-ty-seven is too low"). If you'd like to record your own, ask Mark for a microphone and help with using Windows Sound Recorder, if needed. You can also browse the Internet for interesting and exciting sounds to play when the user guesses correct. Search for "WAV files". (Mark may also put some "istoohigh", "istoolow", and "iscorrect" WAV files on the network.)
(If you remember to ask, I will also tell you how you can also add a MIDI music file to your program so that it plays background music while your user is playing the game. You just have to find a MIDI file and issue one instruction.)