Author Topic: How to call .NET from QB64?  (Read 2686 times)

0 Members and 1 Guest are viewing this topic.

Offline freetrav

  • Newbie
  • Posts: 45
    • View Profile
How to call .NET from QB64?
« on: May 20, 2019, 08:24:55 am »
Inspired by ron77's talking Eliza, I checked some of my older PowerShell work to see how one could do speech without having to install eSpeak. I found that I was basically doing .NET calls to System.Speech.Synthesis.SpeechSynthesizer, which allowed me to call the installed Microsoft voices, which don't sound mechanical the way the eSpeak voices do. Furthermore, calling the .NET speech synthesizer allows you to pass either plain text or SSML,  which allows for some additional vocal expressivity.

Thus the question: Given the PowerShell code

Add-Type -AssemblyName System.Speech
$voice = New-Object -TypeName System.Speech.Synthesis.SpeechSynthesizer
$voice.SelectVoice("Microsoft Server Speech Text to Speech Voice (en-CA, Heather)")
$voice.Speak("Good morning, world!")


How would I do the equivalent in QB64?

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: How to call .NET from QB64?
« Reply #1 on: May 20, 2019, 09:31:28 am »
I got speech working on my Windows 10 system, One-liner jokes:
https://www.qb64.org/forum/index.php?topic=215.msg1080#msg1080

Quote
I have kleptomania, but Im taking something for it.

Here is the crucial call in QB64:
Code: QB64: [Select]
  1. SUB speak (message AS STRING)
  2.     'modifed from "Code" at JB forum
  3.     OPEN "sound.vbs" FOR OUTPUT AS #1
  4.     PRINT #1, "Dim message, sapi"
  5.     PRINT #1, "message=" + CHR$(34) + message + CHR$(34) + " "
  6.     PRINT #1, "Set sapi=CreateObject(" + CHR$(34) + "sapi.spvoice" + CHR$(34) + ")"
  7.     PRINT #1, "sapi.Speak message"
  8.     CLOSE #1
  9.     SHELL "wscript sound.vbs"
  10.  

but Fellippe said it didn't work for him, so ?
(still working for me...)
« Last Edit: May 20, 2019, 09:37:42 am by bplus »

Offline freetrav

  • Newbie
  • Posts: 45
    • View Profile
Re: How to call .NET from QB64?
« Reply #2 on: May 20, 2019, 09:44:00 am »
This is a "hack" not really different in principle from using eSpeak, although accessing the speech assembly through VBScript does allow access to the Microsoft voices; I was hoping for a solution that didn't require 'shelling out' to a non-QB64 executable to actually handle the speech. If it comes to shelling out, I might as well just shell out to PowerShell...

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: How to call .NET from QB64?
« Reply #3 on: May 20, 2019, 11:14:58 pm »
Or, you can look into the hell that is working with Windows API calls. We used to have a working example of calling a midi file, but that somehow went to crap on Windows 10. Frankly, I'd just go with SHELL, as I'm fairly certain there is no native way to do what you are requesting in the latest release of QB64 and I don't expect much in terms of development going forward.

Oh, and if you're actually hearing Microsoft voices... see a priest!

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/