COMPUTE! ISSUE 29 / OCTOBER 1982 / PAGE 205
A Word-Based Voice Synthesizer For The Apple II
David Barron
Spring Valley, NY
Since I purchased my computer I have been interested in voice synthesis. Its applications in CAI, games, and error handling seemed extensive. I decided to apply my newly learned machine language skills to writing my own voice routines.
My routines would have to meet several requirements:
Memory Organization
The memory used to store a vocabulary is divided into 2000-byte blocks. Each of these blocks will be used to store eight, distinct words. Each word will be stored in its own bit of the block of memory. In other words, bit 0 stores word 0, bit 1 stores word 1, and so on. I chose to store the words this way rather than sequentially to reduce the complexity of the program. If I chose the latter way, many rotate commands would be required. These tend to get confusing, and, if you are not careful, very sloppy.
Since a single word rarely contains periods of silence, no data compression is necessary. Again, this simplifies the program. In order to store data in the correct bit, a few things must be done:
Exactly how this is done will be explained in further detail later on.
How Speech Enters And Exits
The data enters into the program through the cassette and exits through the Apple on-board speaker. First let's talk about recording. Location $C060 is the cassette in. When a byte is read from this location, the seventh bit is affected according to the audio signal present. After this location has been sampled, the seventh bit is isolated. It is then plugged into the correct position as explained above.
When in the playback mode, your voice is produced by the on-board speaker. Because the case resonates at certain frequencies, I would recommend hooking up an external speaker, as I have. This greatly improves the quality of any sound produced by the computer, especially voice. One note: when wiring up the speaker, use shielded cable. If you do not, a tremendous amount of RF interference will occur.
The speaker is controlled by location $C030. Every time this memory location is accessed, a click is produced by the speaker. Be careful here. If you use a store instruction to toggle the speaker, it will be toggled twice. This is so because the 6502 does a read before any write. This accesses the location twice, thus producing two clicks.
Getting back to the program – once the correct data byte is loaded, the correct bit is isolated. If this bit is different than the last sample obtained, a change in state has occurred. This will result in the toggling of the speaker, producing a sound. Doing this at the proper rate reproduces the recorded word.
Here's a brief explanation of the machine language "record" and "playback" routines:
Record
The Record routine is probably the most complex part of this program. The entry point is $9000. Here is how it works:
Play
The playback routine is far simpler than the recording routine. Its entry point is $9049.
Entering The Program Into Memory
Type in the BASIC Loader (Program 1) and RUN it to put the machine language program into memory. Then type CALL-151 to enter the monitor. Once this has been done, SAVE the program by typing: BSAVE VOC 1.1OBJ0, A$9000,L$C3.
The next step is to generate the table used by the mask subroutine. To do this, type the following:
* 310 : 01 02 04 08 10 20 40 80To save it, type:
BSAVE TABLE,a$310,L$10
Using The Program
To use the program requires only three simple steps:
A sample program would look something like this:
10 POKE 0,1 : REM WORD 20 POKE 772,10 : REM SPEED 30 CALL 9 * 4096 + 64 + 9 : REM PLAY 40 END : REM DONE
I have included three sample programs:
Program 2: This is a simple routine that speaks any number put in. You must enter the vocabulary from Table 1 before using it.
Program 3: This is a CAI demo. It is an addition quiz that uses Program 1 as a subroutine. This program shares a vocabulary with Program 1. Program 4: This is a vocabulary builder. It should be used to build the vocabulary in Table 1.
I hope you enjoy using these routines, as I have. They make your programs many times more pleasant and impressive.
Table 1.
| WORD NUMBER | WORD |
| 0 | ZERO |
| 1 | ONE |
| 2 | TWO |
| 3 | THREE |
| 4 | FOUR |
| 5 | FIVE |
| 6 | SIX |
| 7 | SEVEN |
| 8 | EIGHT |
| 9 | NINE |
| 10 | TEN |
| 11 | ELEVEN |
| 12 | TWELVE |
| 13 | THIRTEEN |
| 14 | FOURTEEN |
| 15 | FIFTEEN |
| 16 | SIXTEEN |
| 17 | SEVENTEEN |
| 18 | EIGHTEEN |
| 19 | NINETEEN |
| 20 | TWENTY |
| 21 | THIRTY |
| 22 | FORTY |
| 23 | FIFTY |
| 24 | SIXTY |
| 25 | SEVENTY |
| 26 | EIGHTY |
| WORD NUMBER | WORD |
| 27 | NINETY |
| 28 | HUNDRED |
| 29 | THAT |
| 30 | IS |
| 31 | CORRECT |
| 32 | WRONG |
| 33 | TRY |
| 34 | AGAIN |
| 35 | WHAT |
| 36 | PLUS |
| 37 | MINUS |
| 38 | NEGATIVE |
| 39 | WELCOME |
| 40 | MATH |
| 41 | QUIZ |
| 42 | PROBLEM |
| 43 | NUMBER |
| 44 | YOU |
| 45 | GOT |
| 46 | OUT |
| 47 | OF |
| 48 | PROBLEMS |
| 49 | OR |
| 50 | PERCENT |
| 51 | HOW |
| 52 | MANY |