Author Topic: CLR - Text 2 Speech  (Read 6986 times)

stanl

  • Pundit
  • *****
  • Posts: 1812
CLR - Text 2 Speech
« on: June 30, 2013, 05:38:16 am »
Again just practice playing around with different assemblies. IMHO the speech classes in .NET are fairly easy to navigate and incorporate into WB.  I have attached two basic scripts. The first just looks at the default voice. The 2nd iterates all voices. My Win7 laptop only has Microsoft Anna so both scripts end up the same... but for anyone with multiple voices who can try the 2nd script I would appreciate feedback as to whether or not it works.
Code: Winbatch
;***************************************************************************
;** Playing Around with CLR speech  [default voice]
;**
;** Reference:
;**       REQUIRES WinBatch 2013A or newer & CLR version 4.0
;**
;** Stan LittleField, June 29,2013
;***************************************************************************
If Version( )< '2013A'
   Pause('Notice', 'Need 2013A or Newer Version of WinBatch')
   Exit
EndIf
ObjectClrOption("use","System.Speech, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35")
oSpeech = ObjectClrNew('System.Speech.Synthesis.SpeechSynthesizer')
;this is just the default voice, on Win7 it is Microsoft Anna
cVoice = ""
cName=oSpeech.Voice.Name
cVoice=cVoice:"Name: ":cName:@CRLF
cVoice=cVoice:"Culture: ":oSpeech.Voice.Culture:@CRLF
cVoice=cVoice:"Age: ":oSpeech.Voice.Age:@CRLF
cVoice=cVoice:"Gender: ":oSpeech.Voice.Gender:@CRLF
cVoice=cVoice:"Description: ":oSpeech.Voice.Description:@CRLF
cVoice=cVoice:"ID: ":oSpeech.Voice.Id:@CRLF
;this will obtain an object, you can iterate with a ForEach
;If oSpeech.Voice.SupportedAudioFormats.Count != 0 Then cVoice=cVoice:"Audio Formats: ":oSpeech.Voice.SupportedAudioFormats:@CRLF
oSpeech.SelectVoice(cName)
oSpeech.Speak("This is a Test")
oSpeech.Dispose()
oSpeech=0
Message("",cVoice)
Exit
;////////////////////////////////////////////////////////////////////////////////////////////////////
[code=WINBATCH]
;***************************************************************************
;** Playing Around with CLR speech
;**
;** Reference:
;**       REQUIRES WinBatch 2013A or newer & CLR version 4.0
;**
;** Stan LittleField, June 29,2013
;***************************************************************************
If Version( )< '2013A'
   Pause('Notice', 'Need 2013A or Newer Version of WinBatch')
   Exit
EndIf
ObjectClrOption("use","System.Speech, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35")
;create an object for the class that controls speech
oSpeech = ObjectClrNew('System.Speech.Synthesis.SpeechSynthesizer')
cVoices = ""
ForEach v In oSpeech.GetInstalledVoices()
   info = v.VoiceInfo
   cVoices=cVoices:info.Name:@TAB
Next
n=ItemCount(cVoices,@TAB)-1
Message(n,cVoices)                  
For i=1 To n
   oSpeech.SelectVoice(ItemExtract(i,cVoices,@TAB))
   oSpeech.Speak("This is a Test")
   TimeDelay(1)
Next
oSpeech.Dispose()
oSpeech=0
Exit
;//////////////////////////////////////////////////////////////////////////////////////////////////
 
 

[/code]

Deana

  • Wilson WindowWare Tech Support
  • Pundit
  • *****
  • Posts: 1183
  • WinBatch® can do it.
    • WinBatch Tech Support Database
Re: CLR - Text 2 Speech
« Reply #1 on: July 01, 2013, 08:29:11 am »
I tested on my Windows 7 system and had similar results. Thank you for sharing. I added your code to the tech database: http://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/tsleft.web+WinBatch/dotNet/System_Speech+Speak.txt
Deana F.
Technical Support
Wilson WindowWare Inc.

Deana

  • Wilson WindowWare Tech Support
  • Pundit
  • *****
  • Posts: 1183
  • WinBatch® can do it.
    • WinBatch Tech Support Database
Re: CLR - Text 2 Speech
« Reply #2 on: July 01, 2013, 08:40:10 am »
Interesting. I wanted to test on my Windows XP System. The only modification I needed to make was this line:

Changed from 4.0.0.0:
Code: Winbatch
ObjectClrOption("use","System.Speech, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35")

Changed to 3.0.0.0:
Code: Winbatch
ObjectClrOption("use","System.Speech, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35")

One difference is that the default voice is Sam instead of Anna.
Deana F.
Technical Support
Wilson WindowWare Inc.

kdmoyers

  • Sr. Member
  • ****
  • Posts: 511
Re: CLR - Text 2 Speech
« Reply #3 on: July 01, 2013, 09:02:37 am »
Nice! thanks guys!
-Kirby
The mind is everything; What you think, you become.

stanl

  • Pundit
  • *****
  • Posts: 1812
Re: CLR - Text 2 Speech
« Reply #4 on: July 01, 2013, 05:25:11 pm »
Interesting. I wanted to test on my Windows XP System.
One difference is that the default voice is Sam instead of Anna.
Yes, XP has 2 or 3 voices and I believe uses a different SAPI version. I got Dragon Naturally Speaking thinking you could create your own 'voice' for text 2 speech. This site
http://www.zero2000.com/free-text-to-speech-natural-voices.html
lists several 'free' voices, but I was lead to believe the site could not be trusted, so I'm stuck with Anna.

Deana

  • Wilson WindowWare Tech Support
  • Pundit
  • *****
  • Posts: 1183
  • WinBatch® can do it.
    • WinBatch Tech Support Database
Re: CLR - Text 2 Speech
« Reply #5 on: July 02, 2013, 07:49:41 am »
Stan, I don't recommend posting the url of the site that you believe cannot be trusted.
Deana F.
Technical Support
Wilson WindowWare Inc.

stanl

  • Pundit
  • *****
  • Posts: 1812
Re: CLR - Text 2 Speech
« Reply #6 on: July 02, 2013, 04:07:59 pm »
Stan, I don't recommend posting the url of the site that you believe cannot be trusted.
Point taken.