Author Topic: Text to Speech: PowerShell coding assistance, please  (Read 1916 times)

0 Members and 1 Guest are viewing this topic.

Offline GTC

  • Newbie
  • Posts: 49
  • Programmer's motto: *This* time it will work.
Text to Speech: PowerShell coding assistance, please
« on: December 19, 2020, 09:32:01 pm »
In an old and closed thread here:

https://www.qb64.org/forum/index.php?topic=3383.msg126966#new

... Prithak gave us a neat little demo of how to use PowerShell to voice text strings:

Code: QB64: [Select]
  1.    
  2.         INPUT "Enter text: "; text$
  3.         SHELL _HIDE "Powershell -Command " + CHR$(34) + "Add-Type -AssemblyName System.Speech; (New-Object System.Speech.Synthesis.SpeechSynthesizer).Speak('" + text$ + "');" + CHR$(34)


Using that code, I want to change the default voice and I gather that I have to incorporate this "method" but I am seriously ignorant of OO programming technique -- especially in regard to how it maps to QB64 code --  so if someone would show me how to incorporate the following Select.Voice code into Prithak's example, then I will be very grateful.

SpeechSynthesizer.SelectVoice("Microsoft David Desktop")


Offline freetrav

  • Newbie
  • Posts: 45
Re: Text to Speech: PowerShell coding assistance, please
« Reply #1 on: December 21, 2020, 07:49:16 am »
In an old and closed thread here:

https://www.qb64.org/forum/index.php?topic=3383.msg126966#new

... Prithak gave us a neat little demo of how to use PowerShell to voice text strings:

Code: QB64: [Select]
  1.    
  2.         INPUT "Enter text: "; text$
  3.         SHELL _HIDE "Powershell -Command " + CHR$(34) + "Add-Type -AssemblyName System.Speech; (New-Object System.Speech.Synthesis.SpeechSynthesizer).Speak('" + text$ + "');" + CHR$(34)


Using that code, I want to change the default voice and I gather that I have to incorporate this "method" but I am seriously ignorant of OO programming technique -- especially in regard to how it maps to QB64 code --  so if someone would show me how to incorporate the following Select.Voice code into Prithak's example, then I will be very grateful.

SpeechSynthesizer.SelectVoice("Microsoft David Desktop")
You will have to write out a PowerShell script and then invoke it. The PowerShell code you need is
Code: [Select]
Add-Type -AssemblyName System.Speech
$voice = New-Object -TypeName System.Speech.Synthesis.SpeechSynthesizer
$voice.SelectVoice("Microsoft David Desktop")
$voice.Speak("Take that, Goliath!")

The .NET SpeechSynthesizer class also supports SSML (Speech Synthesis Markup Language); I wrote an article about using it (in connection with a ficlang) at http://www.freelancetraveller.com/features/tbb/ssml.html; the article also covers basic speech synthesis in PowerShell.

(For what it's worth, I think you'd be better off directly calling .NET from QB64, if that's possible.)
« Last Edit: December 21, 2020, 11:17:36 am by freetrav »

Offline GTC

  • Newbie
  • Posts: 49
  • Programmer's motto: *This* time it will work.
Re: Text to Speech: PowerShell coding assistance, please
« Reply #2 on: December 21, 2020, 10:03:16 am »
Thank you very much for the reply and suggestions.

Quote
The .NET SpeechSynthesizer class also supports SSML (Speech Synthesis Markup Language); I wrote an article about using it (in connection with a ficlang) at http://www.freelancetraveller.com/features/tbb/ssml.html; the article also covers basic speech synthesis in PowerShell.

when I click that link I get "404: Page Not Available"

Quote
(For what it's worth, I think you'd be better off directly calling .NET from QB64, if that's possible.)

I'd have to study up on that. I was hoping that possibly a line or two could be simply added to Prithak's original code snippet.

Offline freetrav

  • Newbie
  • Posts: 45
Re: Text to Speech: PowerShell coding assistance, please
« Reply #3 on: December 21, 2020, 11:19:02 am »
Thank you very much for the reply and suggestions.

when I click that link I get "404: Page Not Available"

I'd have to study up on that. I was hoping that possibly a line or two could be simply added to Prithak's original code snippet.

Link is fixed; I didn't see that the automatic parser included the semicolon (;) as part of the URL. Sorry about that. :)

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • GitHub
Re: Text to Speech: PowerShell coding assistance, please
« Reply #4 on: December 21, 2020, 12:44:19 pm »
@GTC

Always glad to see someone else on the forum using PowerShell to do stuff. I love PowerShell.
Shuwatch!

Offline freetrav

  • Newbie
  • Posts: 45
Re: Text to Speech: PowerShell coding assistance, please
« Reply #5 on: December 21, 2020, 02:33:25 pm »
@GTC

Always glad to see someone else on the forum using PowerShell to do stuff. I love PowerShell.

I swear by PowerShell. I swear at VBScript.

Offline GTC

  • Newbie
  • Posts: 49
  • Programmer's motto: *This* time it will work.
Re: Text to Speech: PowerShell coding assistance, please
« Reply #6 on: December 22, 2020, 08:13:41 am »
@GTC

Always glad to see someone else on the forum using PowerShell to do stuff. I love PowerShell.

Truth be told, I wasn't even aware of it until I cam across Prithak's post. I was aware of SAPI but I gather that's been deprecated by Microsoft.

I have a simple need for my application to echo start/stop/pause/continue commands vocally so that I can be sure of the app's current run status without having to look at the screen. When it is paused I will have "paused" spoken every X seconds to remind me to continue it when appropriate.

As I have mentioned in another thread, I am also interested in being able to issue those commands vocally so that the app is hands free.

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • GitHub
Re: Text to Speech: PowerShell coding assistance, please
« Reply #7 on: December 22, 2020, 08:24:00 am »
@GTC

Take a look at this
Shuwatch!