' ========================================================================= ' ' File...... Emic_TTS.BS2 ' Purpose... Demonstrates Features of the Emic TTS Platform ' Author.... Parallax, Inc. (Copyright (c) 2004, All Rights Reserved) ' E-mail.... support@parallax.com ' Started... ' Updated... 19 APR 2004 ' ' {$STAMP BS2} ' {$PBASIC 2.5} ' ' ========================================================================= ' -----[ Program Description ]--------------------------------------------- ' ' This program demonstrates the TTS capabilities of the GIS Emic TTS ' module (SIP version). Before running this demo make sure that both ' Emic DIP switches are set to OFF (Hex mode of Emic TTS). ' ' Adding Abbreviations CAUTION: ' ' If you use the AddAbbr command, do so only once. By writing the same ' abbreviation over and over you are simply consuming flash space on the ' WTS701 -- flash that cannot be recovered without device reprogramming. ' -----[ Revision History ]------------------------------------------------ ' -----[ I/O Definitions ]------------------------------------------------- Tx PIN 0 ' connects to Emic SIn Rx PIN 1 ' connects to Emic SOut Busy PIN 2 ' 1 = busy Rst PIN 3 ' low to reset Emic TTS AOut PIN 7 ' audio out from Stamp ' -----[ Constants ]------------------------------------------------------- #SELECT $STAMP #CASE BS2, BS2E T2400 CON 396 TmAdj CON $100 ' x 1.0 (note time adjust) FrAdj CON $100 ' x 1.0 (note freq adjust) #CASE BS2SX T2400 CON 1021 TmAdj CON $280 ' x 2.5 FrAdj CON $066 ' x 0.4 #CASE BS2P T2400 CON 1021 TmAdj CON $3C5 ' x 3.77 FrAdj CON $044 ' x 0.265 #CASE BS2PE T2400 CON 396 TmAdj CON $100 FrAdj CON $0AA ' x 0.665 #ENDSELECT Baud CON T2400 Yes CON 1 No CON 0 ' Emic Commands (Hex Mode) Say CON $00 ' say Engish text Volume CON $01 ' set volume, 0 - 7 Speed CON $02 ' set speed, 0 - 4 Pitch CON $03 ' set pitch, 0 - 6 AddAbbr CON $04 ' add abbreviation DelAbbr CON $05 ' delete abbreviation ListAbbr CON $06 ' list abbreviations Version CON $07 ' get version Reset CON $08 ' soft reset Audio CON $09 ' enable audio in PhT CON $10 ' start of phonetic text Help CON $FE ' display help EOM CON $AA ' end of message OK CON $55 ' "okay" for hex mode ' -----[ Variables ]------------------------------------------------------- cmd VAR Byte ' menu command response VAR cmd ' user response vol VAR Nib ' current volume spd VAR Nib ' current speed ptch VAR Nib ' current pitch eePntr VAR Word ' EEPROM pointer char VAR Byte ' character from EE verData VAR Byte(4) ' version data ' -----[ EEPROM Data ]----------------------------------------------------- Demo1 DATA Say, "I love BASIC Stamps!", EOM Demo2 DATA Say, "The time is 12:45", EOM UseAbbr DATA Say, "Your current speed is 65 MPH", EOM Dial DATA Say, "Dialing", EOM Phone DATA Say, "1-916-624-8333", EOM ' -----[ Initialization ]-------------------------------------------------- Setup: GOSUB Hard_Reset ' restore defaults ' -----[ Program Code ]---------------------------------------------------- Main: DEBUG CLS, ' display options menu "============================", CR, " Emic TTS Demo Menu ", CR, "============================", CR, CR, "[1] Demo 1", CR, "[2] Demo 2", CR, "[A] Abbreviation Demo", CR, "[F] Phonetic demo", CR, "[X] Sound Effects (uses Ain)", CR, CR, "[V] Set Volume (", DEC1 vol, ")", CR, "[S] Set Speed (", DEC1 spd, ")", CR, "[P] Set Pitch (", DEC1 ptch, ")", CR, CR, "[R] Revision data", CR, CR, ">> " DEBUGIN cmd ' get command LOOKDOWN cmd, ["1122aAfFxXvVsSpPrR"], cmd ' convert to number cmd = cmd / 2 ' allow for upper/lower IF (cmd > 8) THEN Main ' validate command BRANCH cmd, [Play_Msg, Play_Msg, Play_Msg, Ph_Demo, Play_SFX, Set_Volume, Set_Speed, Set_Pitch, Get_Rev] GOTO Main ' Process Menu command Play_Msg: DEBUG CLS, "Saying: " LOOKUP cmd, [Demo1, Demo2, UseAbbr, UseAbbr], eePntr GOSUB Print_String LOOKUP cmd, [Demo1, Demo2, UseAbbr, UseAbbr], eePntr GOSUB Say_String GOSUB Check_Busy PAUSE 500 GOTO Main Play_SFX: DEBUG CLS, "Speech and Sound Effects" eePntr = Dial ' say "Dialing..." GOSUB Say_String GOSUB Check_Busy eePntr = Phone ' say phone number GOSUB Say_String GOSUB Check_Busy SEROUT Tx, Baud, [Audio, EOM] ' enable Emic Ain eePntr = Phone GOSUB Dial_Phone ' play DTMF phone number PAUSE 1000 ' ring tone FREQOUT AOut, 2000 */ TmAdj, 440 */ FrAdj, 480 */ FrAdj INPUT AOut ' release SEROUT Tx, Baud, [EOM] GOSUB Check_Busy PAUSE 500 GOTO Main Ph_Demo: DEBUG CLS, "Standard: 'Parallax'", CR SEROUT Tx, Baud, [Say, "Parallax", EOM] GOSUB Check_Busy DEBUG "Phonetic: 'pErAl@ks'", CR SEROUT Tx, Baud, [Say, PhT, "pErAl@ks ", EOM] GOSUB Check_Busy PAUSE 500 GOTO Main Set_Volume: DEBUG CLS, "Enter Volume (0 - 7): " ' prompt user DEBUGIN DEC1 response ' get single-digit input vol = response MAX 7 ' validate SEROUT TX, Baud, [Volume, DEC1 vol, EOM] ' send to Emic GOSUB Wait_OK GOTO Main Set_Speed: DEBUG CLS, "Enter Speed (0 - 4): " DEBUGIN DEC1 response spd = response MAX 4 SEROUT Tx, Baud, [Speed, DEC1 spd, EOM] GOSUB Wait_OK GOTO Main Set_Pitch: DEBUG CLS, "Enter Pitch (0 - 6): " DEBUGIN DEC1 response ptch = response MAX 6 SEROUT Tx, Baud, [Pitch, DEC1 ptch, EOM] GOSUB Wait_OK GOTO Main Get_Rev: SEROUT Tx, Baud, [Version, EOM] SERIN Rx, Baud, [STR verData\4] DEBUG CLS, "Emic HWVER = ", HEX2 verData(0), CR, "Emic SWVER = ", HEX2 verData(1), CR, "WTS701 HWVER = ", HEX2 verData(2), CR, "WTS701 SWVER = ", HEX2 verData(3) PAUSE 3000 GOTO Main END ' -----[ Subroutines ]----------------------------------------------------- ' Reset Emic through serial connection Soft_Reset: GOSUB Check_Busy ' wait for busy to release SEROUT Tx, Baud, [Reset, EOM] ' send soft reset GOSUB Wait_OK vol = 4 ' set pgm vars to defaults spd = 2 ptch = 1 RETURN ' Check status of Emic TTS module ' -- wait until Busy line released by Emic ' -- code as written does not timeout Check_Busy: PAUSE 1 ' allow busy to activate DO WHILE (Busy = Yes) : LOOP ' wait until not busy RETURN ' Wait for okay message ' -- will timeout after 1 second Wait_OK: SERIN Rx, Baud, 1000, TO_Error, [WAIT(OK)] RETURN ' Hard reset ' -- good when comm link is lost Hard_Reset: ' reset to default values LOW Rst ' pull reset line low PAUSE 0 ' ~100 uS pause INPUT Rst ' let reset float GOSUB Wait_OK vol = 4 ' set pgm vars to defaults spd = 2 ptch = 1 RETURN ' Send text string to Emic ' -- put first char of EE string in eePntr Say_String: DO READ eePntr, char ' get char from EEPROM SEROUT Tx, Baud, [char] ' send it to Emic eePntr = eePntr + 1 ' point to next LOOP UNTIL (char = EOM) ' stop when EOM found RETURN ' Print text string in DEBUG window ' -- put first char of EE string in eePntr Print_String: DO READ eePntr, char ' get char from EEPROM IF (char >= 32) AND (char < 127) THEN ' print only ASCII chars DEBUG char ENDIF eePntr = eePntr + 1 ' point to next LOOP UNTIL (char = EOM) ' stop when EOM found RETURN ' Process time-out error TO_Error: DEBUG CLS, "No response from Emic TTS." ' ruh-roh, Shaggy END ' Dials phone string that is saved in DATA statement Dial_Phone: DO READ eePntr, char ' get char from EEPROM IF (char >= "0") AND (char <= "9") THEN ' valid digit DTMFOUT AOut, 200 */ TmAdj, 50, [char - "0"] ENDIF eePntr = eePntr + 1 ' point to next LOOP UNTIL (char = EOM) ' stop when EOM found RETURN