Page 1 of 2

Talking to your apps

PostPosted: Fri Mar 29, 2024 9:40 am
by Antonio Linares
This simple code lets you talk to your apps instead of having to write! :-)

Please test it, I do appreciate your feedback. I think this may be very interesting for our apps!

listen.prg
Code: Select all  Expand view
#include "FiveWin.ch"

function Main()

   local oDlg, oGet, cText := Space( 30 )

   DEFINE DIALOG oDlg

   @ 1, 1 GET oGet VAR cText
   oGet:bGotFocus = { || Listen() }

   ACTIVATE DIALOG oDlg CENTERED

return nil

#pragma BEGINDUMP

#include <windows.h>
#include <hbapi.h>

HB_FUNC( LISTEN )
{
    INPUT inputs[4];

    // Pulsación de tecla Windows
    inputs[0].type = INPUT_KEYBOARD;
    inputs[0].ki.wVk = VK_LWIN;

    // Pulsación de tecla H
    inputs[1].type = INPUT_KEYBOARD;
    inputs[1].ki.wVk = 'H';

    // Liberación de tecla H
    inputs[2].type = INPUT_KEYBOARD;
    inputs[2].ki.wVk = 'H';
    inputs[2].ki.dwFlags = KEYEVENTF_KEYUP;

    // Liberación de tecla Windows
    inputs[3].type = INPUT_KEYBOARD;
    inputs[3].ki.wVk = VK_LWIN;
    inputs[3].ki.dwFlags = KEYEVENTF_KEYUP;

    // Envía las pulsaciones de teclas
    SendInput(4, inputs, sizeof(INPUT));    
}

#pragma ENDDUMP

Re: Talking to your apps

PostPosted: Fri Mar 29, 2024 11:10 am
by Enrico Maria Giordano
What is it supposed to do? It does nothing here. I need a microphone?

Re: Talking to your apps

PostPosted: Fri Mar 29, 2024 11:46 am
by MarcoBoschi
Very very interesting!
How can I test it?
What have I to initializa in my pc?
Windows 10

Bye Marco

Re: Talking to your apps

PostPosted: Fri Mar 29, 2024 12:49 pm
by Antonio Linares
Enrico Maria Giordano wrote:What is it supposed to do? It does nothing here. I need a microphone?


Dear Enrico,

Yes, you need a microphone

Re: Talking to your apps

PostPosted: Fri Mar 29, 2024 12:50 pm
by Antonio Linares
MarcoBoschi wrote:Very very interesting!
How can I test it?
What have I to initializa in my pc?
Windows 10

Bye Marco

Dear Marco,

It is built-in Windows 11. Now sure if it is available in Windows 10.

Just press Windows + h keys and see if you get it

Re: Talking to your apps

PostPosted: Fri Mar 29, 2024 12:58 pm
by Marc Venken
It seems that we have to setup our spoken language in windows. Mine was not setup and I get a system dialog saying to install and download a language pack. No time at this moment. Try later ...

Speech Recognition error...

Re: Talking to your apps

PostPosted: Fri Mar 29, 2024 1:09 pm
by MarcoBoschi
It's amazing It works even in my old console program!
I press Windows H And then I click on microphone on the left
From what I understand it works in every application, as long as the focus is in a text field

Re: Talking to your apps

PostPosted: Fri Mar 29, 2024 1:27 pm
by Antonio Linares
> From what I understand it works in every application, as long as the focus is in a text field

right! Thats why we invoke it when a GET has the focus :-)

Re: Talking to your apps

PostPosted: Fri Mar 29, 2024 2:01 pm
by Enrico Maria Giordano
Ok, it works. There is one thing I don't understand: listening starts automatically only with Harbour but not with xHarbour. Do you know why?

Re: Talking to your apps

PostPosted: Fri Mar 29, 2024 6:50 pm
by Antonio Linares
Dear Enrico,

I think it is a timing issue, maybe we invoke it too soon.

We need to find a way to fine tune it...

Re: Talking to your apps

PostPosted: Fri Mar 29, 2024 7:11 pm
by Boby6Muertos
In my case I managed to include it in my app, with another function name, because it clashed with winsock. I was able to use it with Windows 10, although I did have to activate it using the Windows key + h

Re: Talking to your apps

PostPosted: Fri Mar 29, 2024 7:33 pm
by Enrico Maria Giordano
Antonio Linares wrote:Dear Enrico,

I think it is a timing issue, maybe we invoke it too soon.

We need to find a way to fine tune it...


Yes, I was thinking along the same line. I tried with a call to SysWait() but to no avail. I have to try putting a delay in the C code.

Re: Talking to your apps

PostPosted: Sat Mar 30, 2024 9:32 am
by Jimmy
hi Antonio,

does it also work using 32 Bit or only using 64 Bit ?

Re: Talking to your apps

PostPosted: Sat Mar 30, 2024 9:43 am
by Enrico Maria Giordano
It should work with both 32 and 64 bit. But here it only works with some combination of compilers (MSC, BCC, Harbour, xHarbour) and bits (32, 64), not for all the combinations.

Re: Talking to your apps

PostPosted: Mon Apr 01, 2024 9:36 pm
by TimStone
I tried to test it using my Beelink SER 7 mini-pc. It turned out that the microphone ( on the camera ) doesn't work with that device ... didn't know that. Evidently it's a common problem and they don't have a solution.

SO ... I tried it on my Surface Notebook ( Windows + H ) and it did a nice job of converting voice to text.

I would suggest that when using this in our programs, as you have suggested, then we should have a program wide flag that allows the client to use, or NOT use, voice. Maybe a default on setup, and/or a hot key to toggle it. That way we don't always have a live microphone picking up unwanted comments. Of course, this is a developers task, not something FiveWin needs to handle.

Thanks for the idea.