Translate & Speak (1 Viewer)

isladogs

MVP / VIP
Local time
Today, 15:26
Joined
Jan 14, 2017
Messages
18,186
This sample database builds on the code that @arnelgp used in his sample Language Translator database in this thread Language Translator | Access World Forums (access-programmers.co.uk). Text translation uses the online Google Translate service and was based on that arnelgp found at How to Parse HTML from Description Field - ALM/QC User Discussions - ALM / Quality Center (microfocus.com)

Many thanks to @arnelgp for his input on this topic
As the topic interested me, I've now added several new features, notably the use of text to speech (TTS).

In addition, the following items are included:
a) code to check for an Internet connection when the form is loaded
b) reverse translate - useful for checking accuracy of Google translate and for translating into additional languages
c) copy text to clipboard
d) character count (including spaces etc) - tests indicate a limit of around 9800 characters can be translated. If you exceed that limit, there is no output. Interestingly, the character limit if you type / paste text directly into Google Translate is just 500!

1630492672445.png

Using Text to Speech requires the Microsoft Speech Object Library reference.
Note that there are two different references with that name. Make sure you use the reference shown below:

References.PNG


The selected text is exported to a VB script file (Text2Speech.vbs in the program folder) which is then 'executed' i.e. read aloud in the selected voice
The text to speech function is:

Rich (BB code):
Public Function Text2Speech()

On Error GoTo Err_Handler

Dim J As Long
Dim voc As SpeechLib.SpVoice
Dim strFile As String

IP = Environ("ComputerName")
strFile = CurrentProject.Path & "\Text2Speech.vbs"

'check available voices
Set voc = New SpVoice

For J = 0 To voc.GetVoices.Count - 1
    Set voc.Voice = voc.GetVoices.Item(J)
    If InStr(voc.Voice.GetDescription, LANG) > 1 Then GoTo SetVoice
Next J

J = 0 'use default language if no match found

SetVoice:
'vbs command to send
A = "on error resume next" & vbCrLf & _
" Dim voc" & vbCrLf & _
" Set voc = CreateObject(""SAPI.SpVoice"")" & vbCrLf & _
" Set voc.Voice = voc.GetVoices.Item(" & J & ")" & vbCrLf & _
" voc.speak " & """" & MSG & """" & vbCrLf & _
" CreateObject(""Scripting.FileSystemObject"").DeleteFile strFile"

CreateObject("Scripting.FileSystemObject").OpenTextFile(strFile, 2, True).Write A

'Run the VBS through Wscript via WMI Object Win32_Process
  B = GetObject("winmgmts:\\" & IP & "\root\cimv2:Win32_Process").Create("C:\windows\system32\wscript.exe" & strFile, Null, Null, intProcessID)

If Not GetDefaultVoice Like LANG & "*" Then 'not default language
   If J = 0 And Err = 0 And Not GetDefaultVoice Like LANG & "*" Then 'text can be read but no default voice available
       FormattedMsgBox "Voice not available for " & LANG & _
          "@Text will be spoken in the default language: " & GetDefaultVoice & " @", vbExclamation, "Voice not available"
    Else
       'text can't be read so causing error 5 (handled below)
    End If
End If

'run the script
Shell "wscript " & strFile, vbNormalFocus

Exit_Handler:
    Exit Function

Err_Handler:
   If Err = 70 Or Err = 2465 Then Resume Next
   If Err = 5 Then 'character set not readable so TTS isn't available
      FormattedMsgBox "CRITICAL ERROR" & _
           "@Text to Speech is NOT available for " & LANG & ". @", vbCritical, "Text to Speech error"
    Else
       MsgBox "Error " & Err.Number & " in Text2Speech procedure: " & Err.Description
    End If

    Resume Exit_Handler
End Function

Here is an example of the VB Script file created:

Textt2Speech.PNG


For the best results, install additional voices from text to speech settings
In the above example, the text is spoken in French

If no voice is available for the selected language, the text is spoken in the default language:

VoiceNA.PNG


During testing, I installed voices for all available languages from Windows Settings. There are a total of 75 voices in 48 languages.
For details, see Appendix A: Supported languages and voices (microsoft.com)

Disappointingly only 16 of those voices were available on my test workstations using text to speech:

16 available voices:
0 - Microsoft Hazel Desktop - English (Great Britain)
1 - Microsoft Hedda Desktop - German
2 - Microsoft David Desktop - English (United States)
3 - Microsoft Zira Desktop - English (United States)
4 - Microsoft Helena Desktop - Spanish (Spain)
5 - Microsoft Sabina Desktop - Spanish (Mexico)
6 - Microsoft Hortense Desktop - French
7 - Microsoft Elsa Desktop - Italian (Italy)
8 - Microsoft Haruka Desktop - Japanese
9 - Microsoft Heami Desktop - Korean
10 - Microsoft Paulina Desktop - Polish
11 - Microsoft Maria Desktop - Portuguese(Brazil)
12 - Microsoft Irina Desktop - Russian
13 - Microsoft Huihui Desktop - Chinese (Simplified)
14 - Microsoft Tracy Desktop - Chinese(Traditional, HongKong SAR)
15 - Microsoft Hanhan Desktop - Chinese (Taiwan)


Voices 8, 9, 12, 13, 14, 15 can't be used for TTS in Access as the character set cannot be read
As a result, languages such as Chinese, Japanese or Russian aren't exported to the VBS file
In such cases, a message like this is shown

SpeechNA.PNG



However, in my tests, the following 8 languages all worked successfully:
8 available voices:
0 - Microsoft Hazel Desktop - English (Great Britain)
1 - Microsoft Hedda Desktop - German
2 - Microsoft Zira Desktop - English (United States)
3 - Microsoft Helena Desktop - Spanish (Spain)
4 - Microsoft Hortense Desktop - French
5 - Microsoft Elsa Desktop - Italian (Italy)
6 - Microsoft Paulina Desktop - Polish
7 - Microsoft Maria Desktop - Portuguese(Brazil)


I would be very interested if anyone can explain how to make use of all additional voices which can be installed


NOTE:

1. Four characters used in URLs (&, +, %, #) caused issues for the translate code
The '+' is ignored and any text after '&' or '#' is omitted. Using a % results in all spaces becoming %20 as well
Testing with a phrase like 'You + me & Fred' resulted in the output 'You me' (if 'translated' to English!). Similarly '50% profit #3' became '50%%20profit%20'

I've done a quick work round replacing those 4 characters with very unlikely character strings (at least unlikely in English).
I have also added code to handle line returns correctly in translated text output

See the modified function GglTranslate in modTranslate

2. Similarly, errors occurred when text used in the speech feature included quote marks or line returns.
I have added code to ignore these characters when the text is spoken. For example

Rich (BB code):
Private Sub cmdSpeakTo_Click()
MSG = Replace(Me.txtTo, """", "") 'remove quotes to prevent TTS error
MSG = Replace(MSG, Chr(13) & Chr(10), ".") 'remove line feeds to prevent TTS error
LANG = cboTo.Column(1)
Text2Speech
End Sub

3. The spoken text will be played in its entirety from the VBS script created.
I am not aware of any code which can be used to interrupt/stop it once started. Any info on ways of doing this would be welcomed
 

Attachments

  • Translate&Speak_v3.zip
    93 KB · Views: 723
Last edited:

isladogs

MVP / VIP
Local time
Today, 15:26
Joined
Jan 14, 2017
Messages
18,186
I've made significant improvements to this app including:
1. I've added code to allow users to stop the text to speech if required
2. I've simplified the text to speech code so it now handled within Access rather than using a VB Script
3. As a result, the app can now 'speak' all these languages directly in the listed voices:
0 - Microsoft Hazel Desktop - English (Great Britain)
1 - Microsoft Hedda Desktop - German
2 - Microsoft Zira Desktop - English (United States)
3 - Microsoft Helena Desktop - Spanish (Spain)
4 - Microsoft Hortense Desktop - French
5 - Microsoft Elsa Desktop - Italian (Italy)
6 - Microsoft Haruka Desktop - Japanese
7 - Microsoft Heami Desktop - Korean
8 - Microsoft Paulina Desktop - Polish
9 - Microsoft Maria Desktop - Portuguese(Brazil)
10 - Microsoft Irina Desktop - Russian
11 - Microsoft Huihui Desktop - Chinese (Simplified)
12 - Microsoft Tracy Desktop - Chinese(Traditional, HongKong SAR)
13 - Microsoft Hanhan Desktop - Chinese (Taiwan)


4. A further 69 languages can also be 'spoken' in a 'close' alternative (e.g. Catalan spoken in Spanish) or in the default language - in my case English (Great Britain)

5. That leaves just 29 languages handled by Google Translate which cannot currently be spoken due to issues with the character set used e.g. Arabic / Hindi. I'm hoping to reduce this number still further as voices do exist for some of those languages.
For some unknown reason, Access can't 'see' some of the installed voices e.g. Arabic, Bulgarian, Greek, Hebrew, Norwegian, Vietnamese etc

I will be uploading an updated version in the next few days.
In the meantime, here is a short video demonstrating the app in use


EDIIT 8 Jan 2022 - fixed broken video link
 

Attachments

  • Translate&Speak2.zip
    2.9 MB · Views: 683
Last edited:

isladogs

MVP / VIP
Local time
Today, 15:26
Joined
Jan 14, 2017
Messages
18,186
FURTHER UPDATE 03/09/2021
I found an extremely helpful article explaining why some of the installed voices couldn't be seen by TTS
text to speech - Windows 10 TTS voices not showing up? - Stack Overflow

Basically there are two types on installed voice. Only one of those types is available to TTS.
However, a registry modification allows ALL installed voices to be used by TTS. Hooray!

After updating the registry to include one installed voice only for each language I now have:
38 available voices:
0 - Microsoft Hazel Desktop - English (Great Britain)
1 - Microsoft Naayf - Arabic (Saudi)
2 - Microsoft Ivan - Bulgarian (Bulgaria)
3 - Microsoft Herena - Catalan (Catalan)
4 - Microsoft Jakub - Czech (Czech Republic)
5 - Microsoft Helle - Danish (Denmark)
6 - Microsoft Stefanos - Greek (Greece)
7 - Microsoft Heidi - Finnish (Finland)
8 - Microsoft Asaf - Hebrew (Israel)
9 - Microsoft Hemant - Hindi (India)
10 - Microsoft Matej - Croatian (Croatia)
11 - Microsoft Szabolcs - Hungarian (Hungary)
12 - Microsoft Andika - Indonesian (Indonesia)
13 - Microsoft Rizwan - Malay (Malaysia)
14 - Microsoft Jon - Norwegian (Bokmål)
15 - Microsoft Frank - Dutch (Netherlands)
16 - Microsoft Andrei - Romanian (Romania)
17 - Microsoft Filip - Slovak (Slovakia)
18 - Microsoft Lado - Slovenian (Slovenia)
19 - Microsoft Bengt - Swedish
20 - Microsoft Valluvar - Tamil (India)
21 - Microsoft Pattara - Thai (Thailand)
22 - Microsoft Tolga - Turkish (Turkey)
23 - Microsoft An - Vietnamese (Vietnam)
24 - Microsoft Hedda Desktop - German
25 - Microsoft Hoda - Arabic (Egypt)
26 - Microsoft Zira Desktop - English (United States)
27 - Microsoft Helena Desktop - Spanish (Spain)
28 - Microsoft Hortense Desktop - French
29 - Microsoft Elsa Desktop - Italian (Italy)
30 - Microsoft Haruka Desktop - Japanese
31 - Microsoft Heami Desktop - Korean
32 - Microsoft Paulina Desktop - Polish
33 - Microsoft Maria Desktop - Portuguese(Brazil)
34 - Microsoft Irina Desktop - Russian
35 - Microsoft Huihui Desktop - Chinese (Simplified)
36 - Microsoft Tracy Desktop - Chinese(Traditional, HongKong SAR)
37 - Microsoft Hanhan Desktop - Chinese (Taiwan)


The quality of each voice appears to be excellent. All sound very natural - not at all robotic (unlike ESpeak)

In addition, a further 26 languages have 'close alternatives' that use the same/similar character set e.g. Persian spoken in Arabic,
Another 28 can be read in the default voice (English - GB)
That leaves just 18 of the 110 languages listed that TTS is unable to recognise

I will upload the updated version when I've had time to write an accompanying help file & including modified .reg files
 
Last edited:

isladogs

MVP / VIP
Local time
Today, 15:26
Joined
Jan 14, 2017
Messages
18,186
arabic is not same as persian.
I never said it was. Similarly Catalan isn't the same as Spanish. Nor is Belarusian the same as Russian....etc
Nevertheless, each pair of languages contain enough similarities to be able to use the available language as a reasonably close alternative
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 23:26
Joined
May 7, 2009
Messages
19,169
Nevertheless, each pair of languages contain enough similarities to be able to use the available language as a reasonably close alternative
you should investigate more.
persian cannot be a substitute for arabic.
they are entirely different, even in writing.
you don't want to make stir on arabic world.
even microsoft did not attempt to substitute it.
so you better not, otherwise you will find someone
knocking on your door with strap... on her waist.
 

isladogs

MVP / VIP
Local time
Today, 15:26
Joined
Jan 14, 2017
Messages
18,186
you should investigate more.
persian cannot be a substitute for arabic.
they are entirely different, even in writing.
you don't want to make stir on arabic world.
even microsoft did not attempt to substitute it.
so you better not, otherwise you will find someone
knocking on your door with strap... on her waist.

I always welcome comments .... when they are intended to be constructive!

I have no idea what your native language is or indeed whether you can speak either Farsi or Arabic.
However, I did research all the languages for which there is no available voice with a view to finding possible alternatives

For example:
Farsi (Persian) vs Arabic - similarities and differences
Arabic and Persian (Farsi) are totally different languages, but both with a mostly common alphabet, overlapping vocabulary (nearly all going from Arabic to Persian), and with ties to Islam. The similarity is a bit like that between English and French.
...
Modern Persian (in both Iran and Afghanistan) is written in the Perso-Arabic script, which is the Arabic script but with slight pronunciation modifications, plus a few extra letters.
Farsi vs Arabic Comparison
After explaining that the two languages are in fact different, I then explain that they use the same alphabet. The Arabic alphabet is the basis for multiple languages across the Arabian Peninsula, Middle East, North Africa, and as far east as India and western China. Languages that use the arabic alphabet include Farsi, Kurdish, Pashto, Somali, and Urdu. Even Turkish was written in the Arabic alphabet up until 1928 when Turkey passed a law banning the use of the Arabic alphabet for writing.

Anyway, the alternative voice suggested (Arabic) for Pashto, Persian and Urdu is entirely optional

Do feel free to continue playing with your Arab Strap ... for as long as it gives you pleasure!
 

Attachments

  • Translate&Speak3.zip
    1.6 MB · Views: 404
Last edited:

isladogs

MVP / VIP
Local time
Today, 15:26
Joined
Jan 14, 2017
Messages
18,186
Its taken somewhat longer to complete this than expected as I hit a problem when translating original text in a language using a non-Latin character set e.g. Russian, Chinese, Arabic. In such cases the output had nothing to do with the original text being translated.

After several fruitless hours, the solution was to use a modified version of the code from https://www.codegrepper.com/code-examples/vb/excel+vba+translate+text which uses Excel as an intermediary step

For a more detailed description of the issue and the solution used, see my thread at https://www.utteraccess.com/topics/2061924/posts/2787256

1632126794516.png


1632126836993.png


The app is now complete & I'm currently working on the accompanying help file. Will upload when done

NOTE: As the issue also affects the similar Translate app created by @arnelgp, I have also added a comment in that thread

EDIT
I forgot to mention this earlier:
VB script files are no longer needed for the text to speech feature. I now have more efficient code that doesn't require using any external files
 
Last edited:

isladogs

MVP / VIP
Local time
Today, 15:26
Joined
Jan 14, 2017
Messages
18,186
I have now completed my Translate & Speak application.

As well as all the translation and text to speech features already described above, version 4.3 also includes code which allows all the captions on a form (labels, command buttons, tab controls etc) to be translated to another language. For example:
1632505895720.png

This could be very useful to any developers who need to create translated versions of their applications for use by some clients in other countries.
I intend to add to this idea in a separate application in the near future

In total, Google Translate currently supports 109 languages. If all available voice packs are installed in Windows 10, there will be dedicated voices for around 35 languages and a further 60 languages can be spoken using the alternative voices suggested

The attached zip files contain ACCDE versions of the app for both 32-bit & 64-bit Access.
Both zip files also contain a PDF help file and 34 registry files (.reg).
These can be used to make certain installed voices available for text to speech. Full instructions are provided as part of the PDF help file

An ACCDB version containing all source code for the application can be obtained from:

NOTE This thread is moderated, but I would also welcome any feedback by email or PM

I've also included a link to a new You Tube video that I uploaded earlier today

 

Attachments

  • Translate&Speak_v4.3_32-bit.zip
    1.1 MB · Views: 624
  • Translate&Speak_v4.3_64-bit.zip
    1.1 MB · Views: 642
Last edited:

jaikaoliver

Member
Local time
Today, 08:26
Joined
Nov 18, 2019
Messages
37
I have now completed my Translate & Speak application.

As well as all the translation and text to speech features already described above, version 4.3 also includes code which allows all the captions on a form (labels, command buttons, tab controls etc) to be translated to another language. For example:
View attachment 94776
This could be very useful to any developers who need to create translated versions of their applications for use by some clients in other countries.
I intend to add to this idea in a separate application in the near future

In total, Google Translate currently supports 109 languages. If all available voice packs are installed in Windows 10, there will be dedicated voices for around 35 languages and a further 60 languages can be spoken using the alternative voices suggested

The attached zip files contain ACCDE versions of the app for both 32-bit & 64-bit Access.
Both zip files also contain a PDF help file and 34 registry files (.reg).
These can be used to make certain installed voices available for text to speech. Full instructions are provided as part of the PDF help file

Using an approach regularly used by another long established AWF member, please contact me by email or private message if you would like to obtain a free copy of the ACCDB version of the application.

NOTE: This thread is moderated but I would also welcome any feedback by email or PM

I've also included a link to a new You Tube video that I uploaded earlier today

Greetings @isladogs kindly send me the accdb of this please
its such a powerful tool
 

isladogs

MVP / VIP
Local time
Today, 15:26
Joined
Jan 14, 2017
Messages
18,186
As previously stated, you'll need to send me an email or a PM and I'll explain how you can obtain a copy
 
Last edited:

D_Walla

Member
Local time
Today, 15:26
Joined
Aug 1, 2021
Messages
32
This looks amazing! I use TTS a fair bit because I get tired of reading all day every day, so I've been on the hunt for natural sounding TTS options. In my wildest dreams, I would love to be access the voices being used in the Edge Read Aloud function - the Natural Online language voices available in that are seriously impressive (sorry, Alexa). I know that they're accessible through an API, but it's not the same....
 

isladogs

MVP / VIP
Local time
Today, 15:26
Joined
Jan 14, 2017
Messages
18,186
The natural voices available in Windows 10 are included in the Read Aloud voices in Edge.
The Online voices seem to be about the same in terms of how natural these sound ... which is excellent.

The only additional language voice I found in the Online list was for Swahili.
However, if anyone knows how to download any of the Online voices, do let me know. I'm not aware of an API for this.

I would also be interested to know if Windows 11 has voices for any additional languages not in Win 10
 

isladogs

MVP / VIP
Local time
Today, 15:26
Joined
Jan 14, 2017
Messages
18,186
I've finally uploaded the ACCDE version of my Translate & Speak app to my website:

The ACCDB version can be purchased at a reasonable price from:
 

Users who are viewing this thread

Top Bottom