* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Program  *  MVREADER.PRG                                                  *
* System   *  Micro/Voice for Clipper Summer '87                            *
* Version  *  Version 1.00                                                  *
* Library  *  MVCLIP87.LIB - 06/10/90 1:00a                                 *
* Author   *  Steve Badaracco                                               *
* Notice   *  (c)1990, DataBlaze Solutions, All Rights Reserved             *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*                                                                           *
* This program demonstrates reading text from a disk file with Micro/Voice. *
* Try MVREADER.TXT, which contains words defined in the mini-dictionaries.  *
* When reading text from a file, it is especially important to have a       *
* dictionary present, as we have done here.  A full dictionary is available *
* to registered users of Micro/Voice, as well as a program which allows     *
* you to build a custom dictionary; see the DOC file for details.           *
*                                                                           *
* To compile (requires The Clipper Compiler, Summer '87 Version):           *
*     CLIPPER MVREADER                                                      *
*                                                                           *
* To link for execution (using Microsoft Overlay Linker Version 3.x):       *
*     LINK MVREADER,,NUL,CLIPPER+EXTEND+MVCLIP87/SE:256                     *
* To link for execution (using Turbo Link Version 1.x):                     *
*     TLINK MVREADER,,NUL,CLIPPER+EXTEND+MVCLIP87                           *
* To link for execution (using PLINK86plus Version 2.24 for Clipper):       *
*     PLINK86 FI MVREADER LIB CLIPPER,MVCLIP87,EXTEND                       *
* To link for execution (using Blinker Dynamic Overlay Linker Version 1.x): *
*     BLINKER FI MVREADER LIB CLIPPER,MVCLIP87,EXTEND                       *
*                                                                           *
* To run the demo on the sample text file:                                  *
*     MVREADER MVREADER.TXT                                                 *
*                                                                           *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

parameters filename

if pcount() = 0
   * No parameters from DOS
   ? 'Filename to be read must be specified on the command line.'
   ?
   quit
elseif !file(filename)
   * First parameter was not an existing file
   ? 'File not found.'
   ?
   quit
elseif "?" $ filename .or. "*" $ filename
   * Did you know that Clipper's file() function processes wildcards?
   ? 'No wildcards allowed.'
   ?
   quit
elseif v_init( 'system01.dct', 'mycustom.dct', 1, 23, 2 ) # 0
   * Good Micro/Voice initialization settings for PS/2 Model 55SX
   ? 'Voice initialization error: data file(s) not found.'
   ?
   quit
elseif memory(0) < 12        && a good round number
   ? 'Not enough memory to read a file.'
   ?
   quit
endif

? 'Reading file: "&filename." ... <Esc> to cancel.'

* Open the file
* Remember ... this is just a demo; we area assuming this is a text file.
handle = fopen( filename )
if handle < 0
   ? 'Error opening file.'
   ?
   quit
endif

* Read up to 10K for our demo
thedata = space( 10240 )
fread( handle, @thedata, 10240 )
fclose( handle )
thedata = trim( thedata )

* Main loop -- until end of text or Esc key is pressed
do while ! empty( thedata ) .and. inkey() # 27

   * Parse out next logical line
   crlf = at( chr(13)+chr(10), thedata )
   crlf = if( crlf=0, len( thedata ) + 1, crlf )
   current = ltrim( subst( thedata, 1, crlf-1 ) )
   thedata = subst( thedata, crlf+2 )

   if ! empty( current )    && Don't bother with blank lines

      * Pack the line for Micro/Voice
      packed = v_wpack( current )

      * Display text as read from file
      ? current

      * Display the phoneme string equivalent
      ? v_unpack( packed )

      * Speak it
      v_pkspeak( packed )

   endif

enddo

quit

