locked
Would appreciate some help on LitDev's LDInline functions RRS feed

  • Question

  • Hello,

    I wrote a program in Small Basic to help (Thai) students practice French speaking: I show them a sentence in Thai and/or English and they have to say it in French. By pressing Enter, they can see the correct French sentence. And by clicking an icon (representing a loudspeaker) they can listen to the correct way to pronounce the sentence.

    So far, I created almost 4,000 mp3 files, one for each sentence. And I'm getting a bit bored of doing this, especially since I would have to create a few thousands more for the new lessons.

    I discovered LitDev Extension API [1] yesterday. I suppose I can NOT use LDSpeech [2] to make my program speak French. (It only knows English, right?)

    In HTML, there is a "text to speech" JavaScript called responsivevoice.js [3]. I am wondering if I could use it in Small Basic.

    <script src='https://code.responsivevoice.org/responsivevoice.js'></script>
                <input onclick='responsiveVoice.speak("Hello World");' type='button' value='🔊 Play' />

    I saw that, with LDInline [4], I can "include C#, VB or JScript code to use at runtime".

    So my question is : Is it possible to use LDInline to run my responsivevoice.js JavaScript? And, if yes, how?

    I would highly appreciate if someone could help me start writing the lines I need!

    (Maybe I should add that I don't know anything concerning JavaScript.)

    Many thanks in advance for any help. :-)

    --J.

    [*] Sorry, as a new user, I cannot insert links. Here they are:
    (1) http://litdev.co.uk/LitDev.html
    (2) http://litdev.co.uk/LitDev_LDSpeech.html
    (3) https://responsivevoice.org/api/
    (4) http://litdev.co.uk/LitDev_LDInline.html

    Tuesday, May 23, 2017 5:43 PM

Answers

  • Here is the solution I found to make the French voices "Julie" and "Paul" visible under Small Basic:

    1. Open regedit.

    2. Export
    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech_OneCore\Voices\Tokens\MSTTS_V110_frFR_JulieM
    as Julie 1.reg.

    Export
    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech_OneCore\Voices\Tokens\MSTTS_V110_frFR_PaulM
    as Paul 1.reg.

    3. Open Julie 1.reg and Paul 1.reg with Notepad.

    4. Replace all "Speech_OneCore" with "Speech".

    5. Save the files as Julie 2.reg and Paul 2.reg.

    6. Run those two new files.

    The voices are now seen and usable by Small Basic.

    --J.


    • Proposed as answer by litdev Thursday, July 6, 2017 8:43 PM
    • Edited by John Doe 1960 Saturday, July 8, 2017 10:18 AM
    • Marked as answer by WhTurner33Editor Tuesday, July 18, 2017 10:36 AM
    Thursday, July 6, 2017 7:14 PM

All replies

  • Not sure how to get https://code.responsivevoice.org/responsivevoice.js to work with inline.

    I think the reason is that the inline js only works with js that doesn't use web based functions - these seem to only work in a browser :(

    Your PC may have other language voices, or you can install them.

    You can check which voices are installed with

    voices = LDSpeech.Voices()
    For i = 1 To Array.GetItemCount(voices)
      TextWindow.WriteLine(voices[i])
      LDSpeech.Voice = voices[i]
      LDSpeech.Speak("Hello World")
    EndFor


    • Edited by litdev Wednesday, May 24, 2017 6:29 PM comment about why web js does't work
    • Proposed as answer by litdev Saturday, May 27, 2017 1:32 PM
    Tuesday, May 23, 2017 7:48 PM
  • Another possibility is to use SB to create a simple html file you can then load into a browser.

    quotes = Text.GetCharacter(34)
    CR = Text.GetCharacter(10)
    
    speech[1] = "Hello World"
    speech[2] = "Something Else"
    speech[3] = "More Stuff"
    
    html = "<script src='https://code.responsivevoice.org/responsivevoice.js'></script>"+CR
    For i = 1 To Array.GetItemCount(speech)
      html = html+"<input onclick='responsiveVoice.speak("+quotes+speech[i]+quotes+");' type='button' value='"+speech[i]+"' /><br>"+CR
    EndFor
    
    File.WriteContents(Program.Directory+"\speech.html",html)

    When you load speech.html into a browser you get the following that works OK - you can create the speech array from any source you have.

    Also edit the commands to speak in French using optional speak API syntax defined on the responsivevoice site, for example:

    quotes = Text.GetCharacter(34)
    CR = Text.GetCharacter(10)
    
    speech[1] = "Hello World"
    speech[2] = "Something Else"
    speech[3] = "Bonjour"
    
    html = "<script src='https://code.responsivevoice.org/responsivevoice.js'></script>"+CR
    For i = 1 To Array.GetItemCount(speech)
      html = html+"<input onclick='responsiveVoice.speak("+quotes+speech[i]+quotes+","+quotes+"French Female"+quotes+");' type='button' value='"+speech[i]+"' /><br>"+CR
    EndFor
    
    File.WriteContents(Program.Directory+"\speech.html",html)


    • Edited by litdev Tuesday, May 23, 2017 10:01 PM
    • Proposed as answer by litdev Saturday, May 27, 2017 1:32 PM
    Tuesday, May 23, 2017 9:50 PM
  • Thanks a lot for your precious and kind help.

    Based on your indications, I tried this:
    quote = Text.GetCharacter(34)
    CR = Text.GetCharacter(10)
    
    Text = "Bonjour tout le monde !"
    
    html = "<script src='https://code.responsivevoice.org/responsivevoice.js'></script>" + CR
    html = html + "<body onload = 'responsiveVoice.speak(" + quote + Text + quote + ", " + quote + "French Female" + quote + ");' /><br>" + CR
    html = html + "</body>"
    
    File.WriteContents(Program.Directory + "\HTML\" + Text + ".html",html)
    
    Program.Delay(5000)
    
    LDControls.AddBrowser(800,400,"file:///" + Program.Directory + "\HTML\" + Text + ".html")
    When I open the html file in my browser (Nightly, Chrome or Edge), I get the sound without any problem, but I get an error message with the LDControls.AddBrowser function.


    (Sorry, my system is in French.)

    Would you have any idea to make that work?

    Thanks again in advance for any help. :-)

    --J.
    Monday, May 29, 2017 8:50 PM
  • I spotted this too.  I can't find a reason and nothing by Googling yet.  The browser control I use in extension is totally stanndard .Net so I think it must be something security related preventing js from being run from an external server.

    I can run js that is local to my PC or embedded in html from SB browser, just not js that uses function defined on an external server?

    I will look further but not very hopeful.

    You can start a full brower from SB with:

    LDProcess.Start(Program.Directory+"\speech.html",""

    Tuesday, May 30, 2017 5:26 PM
  • When i use the 'responsivevoice.js'  (or better readable responsivevoice.src.js ) locally from the \HTML\ folder

    html = "<script src='.\responsivevoice.js'></script>" + CR

    ....  ,

    then prior the the upper 'Script Error' a second 'script Error' appears, eg.:

    Line: 8

    Character: 180

    Error: 'console' is not defined

    Code: 0

    URL: file:///..pathTo.../HTML/responsivevoice.js

    The IE-BrowserControl has some limitations and i guess, that the ScriptConsole (window.console) is one of them.

    Also cannot compile the 'responsivevoice.js'  from LDInline, nor jsc.exe.

    First (jsc building) error that appears is also:

    1.   error JS1135: The Variable console was not declared.

    2.  error JS1135: The Variable navigator was not declaed.    3.   etc......

    So i'm afraid that this script will not be able to use from BrowserControl or LDInline at all, because of limitations from the Control itself.

    • Proposed as answer by litdev Saturday, July 1, 2017 12:08 PM
    Tuesday, May 30, 2017 11:06 PM
    Answerer
  • @ papa - I also got the console error when trying a local downloaded copy of the js - javascript relies on browser to do various things - console is not in the required API; most can use it - but apparently not the .Net Browser control.

    For this project I would consider going back and check the LDSpeech option, installing required language packs.


    • Edited by litdev Wednesday, May 31, 2017 5:39 PM
    • Proposed as answer by litdev Saturday, July 1, 2017 12:08 PM
    Wednesday, May 31, 2017 5:39 PM
  • Thanks.

    As you suggested, I’m working on the LDSpeech option. And I have one more question/problem.

    When I go to Microsoft Speech Platform - Runtime Languages (Version 11), I can find the following French Text To Speech package :

    MSSpeech_TTS_fr-FR_Hortense.msi

    Another Microsoft webpage shows that 2 more “text-to-speech (TTS) voices are available in the Windows 10 Creators Update”: Paul and Julie.

    I was able to install those 3 French language packs (Hortense, Paul and Julie).


    My problem is that, when I run the following program in Small Basic:

    voices = LDSpeech.Voices()
    For i = 1 To Array.GetItemCount(voices)
      TextWindow.WriteLine(voices[i])
      LDSpeech.Voice = voices[i]
    EndFor

    ...I only get “Hortense” (and two English voices).

    Is there a way to access “Paul” and “Julie”?

    Thanks again.

    --J.

    Sunday, June 25, 2017 3:36 PM
  • Sorry, no idea why these do not appear for you.  Inside extension I use the following .Net method to get installed voices - Get​Installed​Voices()

    https://docs.microsoft.com/en-us/dotnet/api/system.speech.synthesis.speechsynthesizer.getinstalledvoices?view=netframework-4.7

    Sunday, June 25, 2017 4:04 PM
  • I would guess, that John Doe is on 64bit Windows.

    64 bit voices only appear in

    C:\Windows\System32\rundll32.exe shell32.dll,Control_RunDLL C:\Windows\system32\Speech\SpeechUX\sapi.cpl

    while 32bit voices only appear in

    C:\Windows\System32\rundll32.exe shell32.dll,Control_RunDLL "C:\Windows\SysWOW64\speech\SpeechUX\sapi.cpl"

    -----------------------------------

    voc = LDSpeech.Voices()
    TextWindow.WriteLine(voc)

    -----------------------------------

    'LDSpeech.Voices' ONLY shows installed 64bit voices

    I found this when changed from 32bit to 64bit W7 and there are a some reghacks to show them in a single control panel applet. If it would help i can search for the corresponding regkeys and/or links? (made some notes about that problems anywhere in a txt file on my machine)



    • Edited by Pappa LapubEditor Sunday, June 25, 2017 7:14 PM
    • Proposed as answer by litdev Saturday, July 1, 2017 12:07 PM
    Sunday, June 25, 2017 7:13 PM
    Answerer
  • Thanks for your help. :-)

    I confirm: I'm on a 64 bit Windows 10.

    However, when I installed "Paul and Julie's package", I chose the 64 bit file
        https://www.nvda-fr.org/voix/french_mobile_x64.zip
    and not the 32 bit one
        https://www.nvda-fr.org/voix/french_mobile_x86.zip...

    Let me know if you find a way to make Paul and Julie become visible...

    --J.
    Sunday, June 25, 2017 7:40 PM
  • I'll try to search through my notes, seems to be spread in files all over my fs structure.

    In the meantime here some links i remember:

    Sapi5 (4) voices: Balabolka , DSpeech

    Perhaps try a web search for eg. "use sapi5 voice on 64 bit windows" or similar:

    Some links that might help so far:

    Text to Speech with SAPI

    TTS voices working with Win7/8 64bit

     Windows 7 64 Bit TTS Voice Selection: Problems & Possible Solutions

    SAPI5 voices in Windows 7 64bit

    SAPI5 voices / using 32bit voices

    PS: There's also a Sapi.chm from the MS Speech SDK 5.1 here

    Speech SDK 5.1

    • Edited by Pappa LapubEditor Sunday, June 25, 2017 9:02 PM
    • Proposed as answer by litdev Saturday, July 1, 2017 12:07 PM
    Sunday, June 25, 2017 8:57 PM
    Answerer
  • Thanks Pappa Lapub.

    I had a look at my registry and found "Julie" and "Paul" there:
    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech_OneCore\Voices\Tokens
    HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\SPEECH\Voices\Tokens
    HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Speech_OneCore\Voices\Tokens

    Any idea on what to do?

    I could try to do something close to what is suggested in the link you gave me (TTS voices working with Win7/8 64bit) but I'm afraid of the consequences...

    --J.

    PS: Paul and Julie are not under HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech Server\v11.0\Voices.

    Monday, June 26, 2017 9:04 PM
  • First let me say, that i cannot speak for W8-10 as i'm on W7 64bit.

    I did'nt apply the reghack, because i did'nt work with sapi/voices since changed from W7 32bit.
    NEVER FORGET TO BACKUP ALL AFFECTED KEYS BEFORE !!!!!

    On 32bit all worked 1A and i was rather frustrated when found out about a lot strange incompatibilities and
    laboriousness on 64bit, like a lot of great shell extensions became useless in a 64bit explorer, the regsvr32
    confusion at the beginning, then the sapi/voices stuff, or simply try to open eg.
    C:\Windows\System32\oobe\info\oobe.xml in notepad2 from CmdLine or a StexBar button (the old NP2 is/was 32bit) -> not found.
    ... and a bunch more such annoying things.

    But this reghack also seems no perfect solution (people say/write) and this seems a general problem on 64bit

    Found some other suggestions here (with vb net code)
    Voice not listed in Vista 64 Ultimate drop down
    Windows 7: TTS Software Not Working
    sapi5-voices-for-windows-7 or here
    Microsoft Speech

    The sub-regkeys 'Speech_OneCore' don't exist on my system (but only 'Speech') and the
    'Speech Server' subkeys belong to the 'MS Speech Platform' voices which i have none installed, only Sapi5 voices.

    The default voice is set under
    HKCU\SOFTWARE\Microsoft\Speech\Voices

    1.) usually
    DefaultTokenId=HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\MS-Anna-1033-20-DSK

    After changing to 32bit voice in "C:\Windows\SysWOW64\speech\SpeechUX\sapi.cpl"
    or by a merged .reg file (eg. to ScanSoft Steffi_Dri40_16kHz),
    it reads like: (eg. use  'reg query HKCU\SOFTWARE\Microsoft\Speech\Voices'   ev. with trailing /s)

    2.)
    DefaultTokenId = HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\ScanSoftSteffi_Dri40_16kHz

    But, this 'HKLM\SOFTWARE\Microsoft\Speech\Voices\Tokens\ScanSoftSteffi_Dri40_16kHz'
    key in fact does'nt exist (only under Wow6432Node), but strange thing: nevertheless works with this set
    voice from VBS Script (see below).

    But after running an SB command like:
    LDSpeech.Speak("Scansoft Steffi set")        ' spoken by 'Microsoft Anna'  (the 64bit)

    , the DefaultTokenId entry under HKCU\SOFTWARE\Microsoft\Speech\Voices
    will be set back to default 1.) MS-Anna-1033-20-DSK


    Here is an old SpeakTest.VBS  (1 week) i found (and changed a bit), which works, but has to be called differently for 32bit/64bit usage

    eg. run for 32bit voices:
    C:\Windows\SysWOW64\cscript.exe SpeakTest.vbs        to see Help, or /?, -?
    C:\Windows\SysWOW64\cscript.exe SpeakTest.vbs -l    to list 32bit voices
    C:\Windows\SysWOW64\cscript.exe SpeakTest.vbs -i    for infos about the set/default voice
    C:\Windows\SysWOW64\cscript.exe SpeakTest.vbs "some text"    to speak some text with default voice (0)
    C:\Windows\SysWOW64\cscript.exe SpeakTest.vbs "some text" id    -""-  with voice# ID

    eg. run for 64bit voices:
    cscript.exe SpeakTest.vbs            to see Help, or /?, -?
    cscript.exe SpeakTest.vbs -l            to list 64bit voices
    cscript.exe SpeakTest.vbs -i            for infos about the set/default voice
    cscript.exe SpeakTest.vbs "some text"        to speak some text with default voice (id 0)
    cscript.exe SpeakTest.vbs "some text" id    -""-  with voice# ID

    As said, whenever a 32bit voice is set under
    HKCU\SOFTWARE\Microsoft\Speech\Voices (DefaultTokenId)

    this setting changes to default (64bit MS Anna) after:
    1.) a LDSpeech.Speak  command is run  and/or
    2.) a 64bit command is run, like:  cscript.exe SpeakTest.vbs "some text" id

    Hope this may be of any help.

    PS: Interestingly there's no key under HKCU\Software\Wow6432Node\Microsoft\Speech for any 32bit default voice setting, so, i created one and set it to the right regpath for 32bit voice to

    HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Speech\Voices\Tokens\VOICENAME

    No effect now, but if there's an effect after restart, i'll post it tomorrow.


    • Edited by Pappa LapubEditor Monday, July 3, 2017 10:20 PM
    • Proposed as answer by litdev Thursday, July 6, 2017 8:43 PM
    Monday, July 3, 2017 10:05 PM
    Answerer
  • I've also installed SpeechServer now and 2 voices (they are in 32 and 64bit versions) and made them to show up for

    LDSpeech and narrator.exe (all the 64bit versions), as well as all the 32bit versions in 'SysWOW64...\sapi.cpl' and the 64bit voices in 'system32...\sapi.cpl', and everything works great.

    Can you show, which (voice)keys are directly under your path:

    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\

    eg. key names like   "TTS_MS_en-US_Helen_11.0"  etc. ??

    All of them below this branch (and HKLM\SOFTWARE\Microsoft\Speech Server\v11.0\Voices\Tokens)  can be used by LDSpeech, the (default, from CtrlPanel) sapi.cpl and narrator.

    About the 'Speech_OneCore' (Mobile) voices, you could try yourself, but on W7 there's not even a %windir%\Speech_OneCore folder.

    PS:Your path

    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech Server\v11.0\Voices\Tokens\

    with Harmonie and Hortense is shown above, (Harmonie is missing for LDSpeech, that can be fixed)



    Thursday, July 6, 2017 3:59 PM
    Answerer
  • Here is the solution I found to make the French voices "Julie" and "Paul" visible under Small Basic:

    1. Open regedit.

    2. Export
    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech_OneCore\Voices\Tokens\MSTTS_V110_frFR_JulieM
    as Julie 1.reg.

    Export
    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech_OneCore\Voices\Tokens\MSTTS_V110_frFR_PaulM
    as Paul 1.reg.

    3. Open Julie 1.reg and Paul 1.reg with Notepad.

    4. Replace all "Speech_OneCore" with "Speech".

    5. Save the files as Julie 2.reg and Paul 2.reg.

    6. Run those two new files.

    The voices are now seen and usable by Small Basic.

    --J.


    • Proposed as answer by litdev Thursday, July 6, 2017 8:43 PM
    • Edited by John Doe 1960 Saturday, July 8, 2017 10:18 AM
    • Marked as answer by WhTurner33Editor Tuesday, July 18, 2017 10:36 AM
    Thursday, July 6, 2017 7:14 PM
  • Great to hear, so you did solve it too in the meantime?

    Did'nt know about the transfer copy of the 'Speech_OneCore' voices to the 'Speech' key.

    But this also works for all the voices, which are under

    HKLM\SOFTWARE\Microsoft\Speech Server\v11.0\Voices\Tokens\

    to copy the keys (the ones missing) to

    HKLM\SOFTWARE\Microsoft\Speech\Voices\Tokens

    Also tried to copy (a single voice first) from the 32bit 'WOW6432Node'  paths to the 64bit voices to show up in 64bit sapi.cpl. But this would be no solution. Although the are listed there, they cannot be selected, previewed or used. But collecting the mentioned 64bit voices under HKLM\SOFTWARE\Microsoft\Speech\Voices\Tokens\  works well.

    I've only three  64bit voices installed and they're all in the default applet, LDSpeech and narrator under the same names. And all works great.

      64bit sapi.cpl

    Also renamed the new (SpeechServer) ones, to have shorter names and the german voice (default) listed first.

    PS: Read something about the Eva voice on W10 (locked), if this concerns you, read here

    Thursday, July 6, 2017 8:23 PM
    Answerer
  • Well done John and Pappa.
    Thursday, July 6, 2017 8:42 PM