'
Code:
'Syntax: Text2Speech(sText AS STRING) ' 'Each passed value is spoken in a new thread ' 'Credits: 'Jose Roca SAPI 'http://www.powerbasic.com/support/pbforums/showthread.php?t=21931 ' 'Mel Bishop talking email checker 'http://www.powerbasic.com/support/pbforums/showthread.php?t=40417 FUNCTION PBMAIN& 'Text2Speech.Bas LOCAL s AS STRING,counter AS LONG counter = 0 DO INCR counter s = "Number " + STR$(counter) 'extra space for negative sign s = INPUTBOX$("Thread count" + STR$(THREADCOUNT),"Text2Speech",s) IF LEN(s) = 0 THEN EXIT DO 's = "You typed " + s + " at " + Time$ + " active threads" + STR$(ThreadCount) text2speech s s = "" LOOP IF THREADCOUNT > 1 THEN text2speech STR$(THREADCOUNT) + " threads are still running at" + TIME$ '+ ", thank you Jose Roca and Mel Bishop, Mike Doty" END IF DO UNTIL THREADCOUNT =1:SLEEP 500:LOOP text2speech "Threads ended, so program will now end, thank you" SLEEP 5000 END FUNCTION '----------------------------------------------------------------- SUB text2speech(s AS STRING) 'Talk in background without any globals IF LEN(s) = 0 THEN EXIT SUB LOCAL hThread AS DWORD LOCAL StringAddress AS DWORD StringAddress = VARPTR(s) THREAD CREATE TalkThread(StringAddress) TO hThread IF hThread = 0 THEN ? "Error creating thread" SLEEP 150 THREAD CLOSE hThread TO hThread END SUB '----------------------------------------------------------------- THREAD FUNCTION TalkThread(BYVAL StringAddress AS DWORD) AS DWORD LOCAL p AS STRING POINTER p = StringAddress LOCAL oSp AS DISPATCH SET oSp = NEW DISPATCH IN "SAPI.SpVoice" IF ISFALSE ISOBJECT(oSp) THEN EXIT FUNCTION LOCAL vRes AS VARIANT LOCAL vTxt AS VARIANT LOCAL vTime AS VARIANT vTxt = @p OBJECT CALL oSp.Speak(vTxt) TO vRes vTime = -1 AS LONG OBJECT CALL oSp.WaitUntilDone(vTime) TO vRes END FUNCTION '
Leave a comment: