Author Topic: Text to Speech help  (Read 4540 times)

Magnum

  • Member
  • *****
  • Posts: 2399
Text to Speech help
« on: July 09, 2013, 08:04:13 AM »
I am trying to get this to just read the text when it is run instead of opening a window.

I tried using invoke  Start_sapi5 and Stop_sapi5 but got errors.

Andy

Code: [Select]
; #########################################################################
; Simple Text-to-speech Demo by Siekmanski
; #########################################################################

.386
.model flat, stdcall
 option casemap :none

; #########################################################################

include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
include \masm32\include\ole32.inc

includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\ole32.lib

include coinvoke.inc
include sapi51.inc


; #########################################################################
   WndProc PROTO :DWORD,:DWORD,:DWORD,:DWORD

IDD_TTS    equ 101
IDC_EDIT   equ 1000

       
.data
hInstance      dd 0
Spraak_Buffer  db 1024 dup(0)
Tekst          db 1024 dup(0)
Tekst_intro    db "This is a way to implement a TTS (text to speech) program in assembly.",0
Speech         SpVoice  NULL

.code

start:

; #########################################################################

   invoke  GetModuleHandle,NULL
   mov     hInstance,eax
       
   invoke  CoInitialize,NULL
   invoke  DialogBoxParam,hInstance,IDD_TTS,0,ADDR WndProc,0
   invoke  CoUninitialize         

   invoke  ExitProcess,0

; #########################################################################

Start_sapi5 proc
   invoke  CoCreateInstance,addr CLSID_SpVoice,NULL,CLSCTX_ALL,addr IID_ISpVoice,addr Speech
   ret
Start_sapi5 endp

; #########################################################################

Stop_sapi5 proc
   RELEASE_INTERFACE Speech
   ret
Stop_sapi5 endp

; #########################################################################

WndProc proc hWin:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD

   .if uMsg == WM_INITDIALOG
       invoke  Start_sapi5
       invoke  SetDlgItemText,hWin,IDC_EDIT,addr Tekst_intro

   .elseif uMsg == WM_CLOSE
       jmp     Einde_prog

   .elseif uMsg == WM_COMMAND
           .if wParam == IDOK
               .if( Speech )
                   invoke  GetDlgItemText,hWin,IDC_EDIT,addr Tekst,sizeof Tekst
                   invoke  MultiByteToWideChar,NULL,NULL,addr Tekst,-1,addr Spraak_Buffer,1024
                   coinvoke Speech,ISpVoice,Speak,addr Spraak_Buffer,SPF_DEFAULT,NULL
               .endif
               xor eax,eax
               ret
           .elseif wParam == IDCANCEL
Einde_prog:    invoke  EndDialog,hWin,0
               invoke  Stop_sapi5
               xor eax,eax
               ret
           .endif
   .endif

   xor eax,eax
   ret

WndProc endp

Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

Siekmanski

  • Member
  • *****
  • Posts: 2719
Re: Text to Speech help
« Reply #1 on: July 09, 2013, 06:56:37 PM »
Hello Magnum

Text to Speech without a window.

Creative coders use backward thinking techniques as a strategy.

caballero

  • Member
  • *****
  • Posts: 2153
  • Matrix - Noah
    • abre ojos ensamblador
Re: Text to Speech help
« Reply #2 on: July 09, 2013, 07:33:36 PM »
What impressive, Siekmanski. Is it needed to redistribute anything or just compiling your source (I haven't got masm at hand he he)?
The logic of the error is hidden among the most unexpected lines of the program

Siekmanski

  • Member
  • *****
  • Posts: 2719
Re: Text to Speech help
« Reply #3 on: July 09, 2013, 08:01:00 PM »
Hi avcaballero,

Text to speech is a part of Windows OS.
Creative coders use backward thinking techniques as a strategy.

Magnum

  • Member
  • *****
  • Posts: 2399
Re: Text to Speech help
« Reply #4 on: July 10, 2013, 07:19:48 AM »
Siekmanski,

Thanks a lot.

Andy
Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org