Use microsoft AI Neural TTS on C or REST with ahk only. Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
CaioMartinelli
Posts: 13
Joined: 20 Dec 2020, 11:36

Use microsoft AI Neural TTS on C or REST with ahk only.

Post by CaioMartinelli » 16 Feb 2021, 20:17

HI.

I'm trying to make a TTS script work using remote AI service (because of the high quality), all done with only AHK (send a string, get back a .wav). For now i will use Google, Microsoft Azure or Amazon Polly as they all have free limits per month and great quality. All of them have good documentation for traditional languages, especially the one from Microsoft.

On Microsoft website there is how to make it work for some languages including C (I read somewhere that AHK has a type of C converter), so the question is: Just looking at this code, is possible to adapt the C code below for AHK? Maybe the REST via GET is easier? For now i just want to know it and ill search and work on it to make it work soon or later. Fell free to help more if you can, i will be grateful.

The end objective is simple: (Send a string and get back a .wav, all with ahk.)


C

Code: Select all

public class Program 
{
    static async Task Main()
    {
        await SynthesizeAudioAsync();
    }

    static async Task SynthesizeAudioAsync() 
    {
        var config = SpeechConfig.FromSubscription("YourSubscriptionKey", "YourServiceRegion");
        using var audioConfig = AudioConfig.FromWavFileOutput("path/to/write/file.wav");	
        using var synthesizer = new SpeechSynthesizer(config, audioConfig);	
        await synthesizer.SpeakTextAsync("A simple test to write to a file.");
    }
}
 
REST

Code: Select all

curl --location --request POST 'https INSERT_REGION_HERE.tts.speech.microsoft.com /cognitiveservices/v1'  Broken Link for safety \
--header 'Ocp-Apim-Subscription-Key: INSERT_SUBSCRIPTION_KEY_HERE' \
--header 'Content-Type: application/ssml+xml' \
--header 'X-Microsoft-OutputFormat: audio-16khz-128kbitrate-mono-mp3' \
--header 'User-Agent: curl' \
--data-raw '<speak version='\''1.0'\'' xml:lang='\''en-US'\''>
    <voice xml:lang='\''en-US'\'' xml:gender='\''Female'\'' name='\''en-US-AriaRUS'\''>
        my voice is my passport verify me
    </voice>
</speak>' > output.wav
Source: https://docs.microsoft.com/en-us/azure/ ... age-csharp

Thanks!


User avatar
CaioMartinelli
Posts: 13
Joined: 20 Dec 2020, 11:36

Re: Use microsoft AI Neural TTS on C or REST with ahk only.

Post by CaioMartinelli » 17 Feb 2021, 00:22

Hi BoBo. Yes, i know about these (i use a modified version of Learning One version), what i need is a "...TTS script work using remote AI service (because of the high quality)..." . The windows version is crappy in quality compared to ones that uses "Neural AI" done by MS, Google and Amazon and their "neural" network. The way to use those is with that codes that i posted (plus VB, Python, Java and JS) what i want to know is if just looking at it, there is possible way "convert" or use them in some way with AHK only. I really think that REST can but not sure of C.

gregster
Posts: 8991
Joined: 30 Sep 2013, 06:48

Re: Use microsoft AI Neural TTS on C or REST with ahk only.  Topic is solved

Post by gregster » 17 Feb 2021, 00:33

Generally, you should be able to run the curl request via command line from AHK (run), although you might have change some syntax or escape certain chararacters. I would start with basic curl actions to figure the syntax out (there are probably some examples on these forums).

It should also be translatable into a WinHttp request.

User avatar
CaioMartinelli
Posts: 13
Joined: 20 Dec 2020, 11:36

Re: Use microsoft AI Neural TTS on C or REST with ahk only.

Post by CaioMartinelli » 17 Feb 2021, 14:20

gregster wrote:
17 Feb 2021, 00:33
Generally, you should be able to run the curl request via command line from AHK (run), although you might have change some syntax or escape certain chararacters. I would start with basic curl actions to figure the syntax out (there are probably some examples on these forums).

It should also be translatable into a WinHttp request.
I'm thinking this would be the best way to go too. Thanks man! Just to know, do you know anything about using C codes in AHK with something like a converter or adapter? I think I read something about it here a while ago but never needed anything like it until now.

gregster
Posts: 8991
Joined: 30 Sep 2013, 06:48

Re: Use microsoft AI Neural TTS on C or REST with ahk only.

Post by gregster » 17 Feb 2021, 14:53

well, you can execute machine code via AHK (usually done for higher execution speed). Afaik, that said machine code is usually created by feeding C code into a machine code generator (online or offline). But iirc, there are different flavors or dialects of C. Anyway, I am not really up-to-date - my C/C++ adventures date back at least 20 years :problem:

One (random) search result from our forums would be https://www.autohotkey.com/boards/viewtopic.php?f=6&t=83719&p=366746&hilit=mcode#p366746
If that makes sense in this use case, I don't know. But it's probably not necessary, at least not for speed.

Others might want to chime in.

gregster
Posts: 8991
Joined: 30 Sep 2013, 06:48

Re: Use microsoft AI Neural TTS on C or REST with ahk only.

Post by gregster » 17 Feb 2021, 14:57

Afaics, your code above is C# code, not plain C. That will further complicate matters.
Afaik, curl is part of today's Win10, and there are some winHttp-COM examples on these forums. I would rather try those ways.

User avatar
CaioMartinelli
Posts: 13
Joined: 20 Dec 2020, 11:36

Re: Use microsoft AI Neural TTS on C or REST with ahk only.

Post by CaioMartinelli » 17 Feb 2021, 20:38

gregster wrote:
17 Feb 2021, 14:53
well, you can execute machine code via AHK (usually done for higher execution speed). Afaik, that said machine code is usually created by feeding C code into a machine code generator (online or offline). But iirc, there are different flavors or dialects of C. Anyway, I am not really up-to-date - my C/C++ adventures date back at least 20 years :problem:

One (random) search result from our forums would be https://www.autohotkey.com/boards/viewtopic.php?f=6&t=83719&p=366746&hilit=mcode#p366746
If that makes sense in this use case, I don't know. But it's probably not necessary, at least not for speed.

Others might want to chime in.
gregster wrote:
17 Feb 2021, 14:57
Afaics, your code above is C# code, not plain C. That will further complicate matters.
Afaik, curl is part of today's Win10, and there are some winHttp-COM examples on these forums. I would rather try those ways.
Ah, so it is done through machine code, interesting to know that it is a possibilitie, I will study about it. I agree that in this case the best way should be via curl as it is more simpler, with more information and examples of its use with ahk. Thanks man!

BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Use microsoft AI Neural TTS on C or REST with ahk only.

Post by BoBo » 02 Dec 2021, 08:17

@CaioMartinelli - this might be of use for you (as long as you won't stretch its capacity to the max. It's only the demo form!)
viewtopic.php?f=76&t=97323

Post Reply

Return to “Ask for Help (v1)”