Speaking in Greek

I am trying to get XOJO to say some words in Greek. System.speak doesn’t seem to let me choose a language or voice. So I was looking to incorporate javascript. If I load this html file directly into Safari, it says the word for No in Greek.

<html><header>
<script>
function speakGreek(text) {
  const synth = window.speechSynthesis;
  const utterThis = new SpeechSynthesisUtterance(text);
  utterThis.lang = 'el-GR';
  synth.speak(utterThis);
}
</script>
<header>
<body onLoad="speakGreek('Όχι');">
</body></html>

However, if I load the file into an XOJO desktop.htmlviewer it SPELLS the word letter by letter rather than saying the word itself.

var html as string
html = speak1
Var f As FolderItem = FolderItem.TemporaryFile
HTMLViewer1.loadpage(html, f)

Any suggestions? I’m sure MBS could do it, but that is not a viable solution for this project. Frankly, I might just bypass XOJO entirely on this one if a solution is not close at hand.

Greek caught my attention :yum:
If you’re on Windows, take a look at this thread
There’s a code snippet there that allows you access to the Windows system languages.
Then your problem becomes installing a Greek language voice. They’re referred to as “Legacy Voices”
It seems that there is a male Greek voice (Stefanos) supported, but I wasn’t able to make use of it. Maybe it has to do with my edition of Windows and you’ll have better luck.
But accessing system voices via an OLE object no longer keeps you tied to whatever is behind System.Speak of the Xojo framework.
Good luck with it :slight_smile:

-edit- just noticed that you’ve mentioned Safari, so you’re probably on a Mac

Thanks. I had been looking at that. Unfortunately, I’m working on a Mac.

In a Mac you will need to use Declares. And the target machine must have a proper “voice” for the target locale. Here is a start point for your research:

The good news is that this is certainly possible with Declares. Here’s an example project.

speech.xojo_binary_project.zip (5.9 KB)

NOTE: If you don’t specify a voice, SpeakText will raise a RuntimeException if it can’t find a voice that’s compatible with the language you supply

4 Likes

i guess you meant head.

you will use xojo to transtale text to voice or just play a simple audio file?

I will check it out but it will be an adventure since I’ve never looked into Declares before.

re: Header, right you are although it has no change after correcting it.

The goal is just to have the program speak the text (single words and short phrases) I feed into it. I can make it work using javascript without using XOJO if I hard code the words/phrases into an array within an html file, but I really want to store and retrieve the words/phrases using a DB. Unfortunately, I don’t know how to get the words out of the DB using simple JS. I can do it if I also write some PHP scripts, but I was hoping to use XOJO just to make myself a better user interface. So I’ve looked into:

  1. hard-coding into an html file using hard-coded js arrays/objects which currently works but is a pain to update and track my progress since I don’t know how to get html/js to work with a DB without PHP or XOJO

  2. working with XOJO, mysql, and js, which does what I want except that it SPELLS the word in greek rather than just pronounce it.

  3. work with mysql, html, js and php which I am pretty sure will work but is not satisfying and has too many files and processes to suit my taste for simplification.

@Greg_O

Thanks very much for the code. It seems to work very well. I must say that having never worked with Declares I probably would never have been able to make it work on my own. So this is tremendous. Thanks again.

1 Like

this pro and contra follow us developers day by day.

is it not possible that xojo auto declare all methods?
and we just use:
Include Lib “Foundation”

I’m not sure what you’re talking about, but including all methods in Foundation would not get get you speech synthesis anyway.

OT
Include Lib “SomeLibrary”
similar than in python for modules import matplotlib
or using ocx in vb6, there was somehow a method description with the library.
no need do declare all methods manually.

Import and include are usually used to bring in code that will be compiled/recompiled/cached/used.

It brings in “python code” with all declarations, you can even see the code that runs it. That’s why you don’t need to explain the call, that’s not a DLL or unix like shared lib.
Python is kind of harder than Xojo for such, that’s an extensive topic:

Those are COM/OLE objects, that’s another topic. Xojo have them covered. Once they are registered in a system, Xojo can access them.

https://documentation.xojo.com/api/windows/oleobject.html

For shared libs, Xojo uses kind of the same syntax VB6 had.

The binary lib does not carry information for specific languages being able to infer proper signatures, data types, etc alone. You must know them, name them as you wish, and obey the IO structures as planed by the author of the library (match data, sizes and alignments).

Check how other languages do it. Load and use DLLs / SOs. Xojo isn’t very different.
Your examples are for “other things”.

I still have no idea what you’re talking about

I believe he is saying that Xojo should expose methods in said library

Good luck with that

A standard dynamically loadable lib exposes the exported function names, but nothing about the parameters or returned values, those you need to know and write a proper compatible parameter list in your “compatible language” using compatible call convention, usually C convention.

@Rick_Araujo
was not me asking :grinning:

I know, I just extended your understanding with extra explanation for readers.