|★ CODING ★ LISTINGS ★ Speech generator ★|
|Rsx - Speech Generator|Popular Computing Weekly)||Coding Listings|
The program presented here allows you to add speech synthesis easily to any Basic program - no extra hardware is required and the program will run on any Amstrad CPC. The method used to generate speech is that of 'Digital Recording'. The advantage of this technique over allophone methods is that the 'accent' of the speech can clearly be heard - for example, a male voice is clearly distinguishable from a female voice. The disadvantage of this method is that it is relatively expensive in terms of memory usage.
The speech is sampled (recorded) from the cassette deck (built in on the 484. external on the other machines) and is reproduced by software using channel B of the sound chip this gives equal output to left and right speakers if played back through a stereo amplifier. To use the program, type in the basic loader program taking care with the data statements. If you have made no mistakes then two new RSX commands are added to Basic, these are |RECORD and |REPLAY. The |RECORD command has the following format: |RECORD, start, length where 'start' is the address from where incoming data is to be stored, and 'length'is the number of bytes to be stored. As the program itself sits at the top of Ram from 42000 onwards, a good place to start putting data is at 30000 - remember to lower HIMEM first. For example, record yourself saying "3-2-1 Popular Computing" on cassette - the louder and clearer the better put this tape in the Amstrad tape deck and type the following; MEMORY 29999: |RECORD,30000,10000.
The cassette motor is turned on and a message to 'Press Enter to start recording' is displayed - this is to enable you to position the tape ready to input the speech. As you hear "one", press Enter and the sound from the cassette will be sampled and stored in RAM.
Now to replay this sound use the |REPLAY command as follows; |REPLAY,30000,10000 and you should be able to recognize yourself saying "Popular Computing" fairly clearly. Replay can also take a third optional parameter to specify volume. If this is left out. as in the example above, then a default value of seven is assumed, but you may specify any volume from 0 to 15. try; |REPLAY,30000,10000,15. and you will hear "Popular Computing" at twice the volume.
It soon becomes apparent that the more sound you wish to store, the more Ram it uses. In fact, about one second of speech uses about 1K of RAM. Of course, you can store any number of separate sounds as long as you note the start and length addresses. For example. in a game you might want lo have the computer say "CameOver"and "WellDone"at appropriate points. This speech could be pre-sampled from tape and saved as a binary file -loaded in with the game. Then, using appropriate addresses with the |REPLAY command within the game will allow the phrases to be spoken at the correct time.
As the program is so time critical it must run with interrupts disabled whilst sampling and reproducing the sound. Therefore the sound chip is accessed directly rather than by using the OS routine MC-SOUND-REGISTER.
Experience has shown that anything recorded at a level of less than 0 db will be ignored by the cassette hardware, therefore speech to be sampled should be recorded at a higher level than normal (the higher the better). Although the program can sample any sound from the cassette deck. I have found that only clear speech with little background noise can be satisfactorily reproduced.
There are countless uses of speech synthesis within all types of programs, limited only by your imagination, and your Ram!