Title    : SpanTran Spanish Speech    | Electronic Arcs
By       : Chris Saulit               | Volume 1, Number 3 (July 1987)
Filename : Public-Domain4             | (c) 1987 by Brad Grier & Authors
----------------------------------------------------------------------------

SPANTRAN -- WHAT IS IT?
~~~~~~~~~~~~~~~~~~~~~~~
    In a nutshell: The Amiga can speak English...  SpanTran is a program
which, when installed, enables the Amiga to speak Spanish.  In addition,
once SpanTran is installed, ANY application that uses the Amiga's
English-to-Speech translation capabilities will be able to speak Spanish.
This includes the AmigaDOS `say' command, SpeechToy, InfoMinder,
AmigaBASIC, the various public domain and commercial talking terminal
programs and word processors, and numerous other programs.

    Not to be confused with English-to-Spanish or Spanish-to-English
language translation, SpanTran takes Spanish text and, by applying the
rules of Spanish pronunciation, converts it into Spanish speech.  Without
SpanTran, if the Amiga tried to read Spanish text it would read the text as
if it were English, causing most everything to be mispronounced.  (Try it).

    For those of you who speak Spanish well, I hope SpanTran will be useful
to you.  For the rest of you, perhaps you will find this article interesting
and informative, and the program entertaining.

    This article describes a few of the main issues involved with SpanTran,
the actual source code and executable can be found in a separate archive,
also distibuted with the July 1987 issue of Electronic Arcs.


WHY SPANISH?
~~~~~~~~~~~~
    Spanish was chosen primarily because of its simplicity.  Spanish
pronunciation closely resembles its lexical representation; that is, the
words are spoken as they are spelled.  English, on the other hand, no
longer has a strong correlation between pronunciation and spelling.
English pronunciation has changed significantly over the years but the
spelling does not reflect this change, it has remained constant.  With
Spanish, therefore, it is relatively simple to transcribe a word into its
phonetic representation.

    Unfortunately, there are not many Spanish speaking people up here in
Edmonton (much less any who own Amigas), I suspect this to be different in
other geographical locations where this magazine is distributed.

    And lastly, it is rather amusing to hear the Amiga pronounce one of
Madonna's latest hits, "La Isla Bonita," better than our local radio
announcers!


AMIGA SPEECH -- AN OVERVIEW
~~~~~~~~~~~~~~~~~~~~~~~~~~~
    The speech system on the Amiga is elegant.  Using the AmigaDOS `say'
command, you can type in an English sentence, and moments later listen to
the words being spoken almost effortlessly by the Amiga.  Hidden from you
are the details, the several steps that are present in this process, which
are done every time the Amiga speaks.

    First, rules are applied to the English text to determine its
pronunciation, deriving a phonetic transcription of the text.  This
transcription consists of a series of phonemes, an abstraction of the
individual sounds present in speech. These phonemes are then converted into
sounds, the process known as speech synthesis.  Finally, the audio
capabilities of the Amiga are used to play the sounds which form the words
and sentences that you hear and recognize as speech.

    The two major components comprising the Amiga speech system are the
Narrator Device and the Translator Library.

    The Narrator Device utilizes the audio capabilities of the Amiga to
produce speech -- it is the speech synthesizer.  It creates sounds which
mimic the phonemes of human speech.  These phonemes can be strung together
to form words and sentences.  The speech model supports about fifty
phonemes, which include all the basic vowel and consonant sounds used in
English.  However, the phoneme choice is slightly less well-suited to
Spanish, as will be demonstrated shortly.  By passing a phonetic
representation of an utterance to the Narrator Device, the utterance will
then be spoken by the Amiga.

    The Translator Library is responsible for the conversion of English
text into a phonetic representation, which is then suitable for use as
input to the Narrator Device.  This "translation" process involves the
application of rules to the text to ultimately determine its pronunciation.
With English, however, the rules are quite complex.  In fact, some words'
pronunciations cannot even be determined by ANY rules without considering
the context in which that word appears... for example, the word `read' is
pronounced differently in the following two sentences:  "I read a book
yesterday," and "I can read."

    The phonetic representation used by the Amiga is an extended version of
Arpabet, a phonetic alphabet in which uppercase letter(s) are used to
represent phonemes.  Linguists use phonetic alphabets to represent
utterances, the most common being IPA (International Phonetic Alphabet),
but it uses specialized symbols which are not nearly as easily represented
by the Amiga as plain ASCII text (which Arpabet uses).


AMIGA LIBRARIES
~~~~~~~~~~~~~~~
    Amiga libraries are implemented in such a way that the absolute
location need not be known to call a routine.  A jump table is maintained
for each library, which consists of a set of jump instructions to the
actual routines themselves.

    In a `C' program, if you call one of the Amiga ROM Kernel routines, say
for example OpenWindow(), what happens is that the function OpenWindow() is
called, but all that this function does is to take the parameters you pass
and puts their values into the proper address/data registers for that
routine, then it calls the actual code for the routine by indexing into the
jump table, or "Library Vector Table".  (Note that in order for this
process to work properly, the Library Vector Table must be made available -
achieved via the OpenLibrary() function which returns the Library Base
Pointer (and also fetches the library from disk, if it is disk-resident)).

    This method of implementation of Amiga libraries offers numerous
advantages.  For example, with every release of the Amiga system software
(e.g. 1.2), the library vector tables are essentially identical to those of
the previous release (e.g. 1.1) except, in some cases, with the addition of
new entries in the vector table necessitated by new routines in the ROM
Kernel.  So, for the most part, if a `C' program that uses the Amiga ROM
Kernel routines were developed in one release of the system software, it
should continue to operate in a different release without modification
(e.g. relinking).  (Of course, the program might not operate across
different releases if it did something nonstandard, or if some actual ROM
routines were buggy in one release and not another).

    Another advantage with the Amiga library system is that by changing the
entries in a Library Vector Table, you can actually replace the library
routines with your own.  By doing this, everything that is running on the
Amiga (even the Amiga system software itself) that calls a routine which
you replaced with one of your own, will then be executing YOUR code.  A
number of public domain programs do this, some may be familiar to you:
Larry Phillips (a sysop of CompuServe's AmigaForum) wrote a program that
replaces the Intuition routine DisplayBeep() (which flashes the screen)
with his own routine that produces an actual audible >>BEEP<<.  Another, by
John Hodgson, intercepts all Intuition OpenWindow()/CloseWindow() calls,
and "blossoms/decays" every window that opens or closes.  SpanTran replaces
the Translate() routine in the Translator Library with one that is
functionally similar, except that instead of taking text and determining
an English pronunciation, SpanTran takes text and determines a Spanish
pronunciation.  Therefore, any application that uses the Translate()
function when SpanTran is installed will be executing the SpanTran()
function instead.

    The SetFunction() routine enables you to change an entry in a Library
Vector Table, thereby replacing a library routine.  All that you need to
know is the Library Base Pointer (obtained via OpenLibrary()), the Library
Vector Offset of the function (for which every system routine has a
symbolic name -- Translate()'s Library Vector Offset is LVOTranslate), and
the address of the routine you wish to replace it with.  See the program
`interceptor.c' for a working example.  SetFunction() also does other
necessary actions, such as recomputing the library's checksum and
forbidding multitasking while it is changing the Library Vector Table.

    Because the Amiga is a multitasking system, there could very well be
more than one task using SpanTran at once.  The code must therefore be
re-entrant, concurrent invocations of SpanTran must work correctly for each
task.  This is accomplished by simply ensuring that the only global
variables used are constants.  Any variables used must be unique to each
task.  By making these variables local to each function, they will appear
on each task's own stack.


THE SPANISH LANGUAGE
~~~~~~~~~~~~~~~~~~~~

    Following is a very brief description of some of the basics of Spanish.

    I. Pronunciation
    ----------------

    Spanish contains the following letters; most are simple, some are
compound (consists of more than one letter).  The letters `w' and `k' can
be included, but are found usually only in foreign words.

    VOWELS:     a e i o u
    CONSONANTS: b c ch¹ d f g h j k² l ll¹ m n ñ p q r rr¹ s t w² x y z

        ¹compound letter
        ²foreign letter

    The pronunciations for these letters is relatively straightforward.
Refer to the program file `SpanTran.c' for the rules used (which you can
change if you like).

    The vowel phonemes supported by the narrator device were chosen to
model English speech effectively.  Unfortunately, Spanish vowel sounds
are a little bit different than English.  In Spanish, they are "pure",
there isn't a "blending" as found in English.  In the English word "go",
the `o' is pronounced as if there were a `w' at the end.  In Spanish,
the `o' would not have the `w' sound at the end.

    Some consonant sounds present in Spanish are absent or rare in English.
Fortunately, the narrator device supports most of them.  The letter `rr' is
a tongue trill, a rapid vibration of the tongue against the roof of the
mouth.  This sound was simulated by sticking together a series of tongue
flaps (one vibration) with the `r' sound.

    II. Word Stress
    ---------------

    Unlike our beloved English language, Spanish rules for word stress are
very simple, consistent, and unambiguous.

    (i)   If a word ends in a vowel, `n' or `s', then stress the penultimate
          (next to last) syllable.
    (ii)  If a word ends in a consonant (except `n' and `s'), then stress
          the last syllable.
    (iii) For any exceptions to the above rules, the stressed syllable is
          explicitly indicated with a grave accent (´).

    Examples:

        sombrero (i), vivir (ii), lápiz (iii)
        sombrEro      vivIr       lApiz
             ^           ^         ^             <-- stressed syllables


SUMMARY
~~~~~~~
    The Amiga library system is very well integrated.  In addition to the
capabilities offered by the Narrator Device and Translator library, it was
an easy job to write a program to enable the Amiga to pronounce Spanish.
And the fact that it allows Spanish pronunciation with any application is
just added bonus.

    SpanTran was developed primarly as an exercise or programming project
on the Amiga, not specifically needing the end result itself.  Therefore,
I'd be interested in hearing if anybody finds this program useful, or has
any comments or suggestions.





    You can write to me as follows:

    Chris Saulit                CIS:        73007,3267
    10610 - 80 Street           BITNET:     CSAULIT@UALTAVM
    Edmonton, Alberta           uucp:       ...!ihnp4!alberta!uqv-mts!saul
        Canada.   T6A 3K1


                ¡Muchas gracias, señoras y señores!

