Fun time with speak function

Fun time with speak function

Anonymous
Not applicable
1,440 Views
14 Replies
Message 1 of 15

Fun time with speak function

Anonymous
Not applicable

Hi guys... I have found thread over at Swamp for integrating SPEAK function into ACAD.

http://www.theswamp.org/index.php?topic=14549.75

 

I am trying to make it work but my skills are still quite poor.

 

I would like to make acad say Kaboom when I explode ...

I did this simple code but it is not really synchronized 🙂 it works , but tone is too low and it says "Kaboom" before i actualy select and explode object.

 

(defun C:exx () (command "explode")
(setq sapi (vlax-create-object "Sapi.SpVoice"))
(vlax-invoke sapi "Speak" "Kaboom" 0)
(vlax-release-object sapi))

 

I would like to see principle , to have simple function that after it is done says something or even better play a sound. Also I would need to have volume up.

 

Thanks
Jan

0 Likes
1,441 Views
14 Replies
Replies (14)
Message 2 of 15

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

.... it says "Kaboom" before i actualy select and explode object.

 

(defun C:exx () (command "explode")
(setq sapi (vlax-create-object "Sapi.SpVoice"))
(vlax-invoke sapi "Speak" "Kaboom" 0)
(vlax-release-object sapi))

....


As to that issue only, you would need to let the Explode command be completed before moving on to the Speak part.

 

  ....  (command "_.explode")

  (while (> (getvar 'cmdactive) 0) (command pause))

  (setq ....

Kent Cooper, AIA
0 Likes
Message 3 of 15

Anonymous
Not applicable

THX Kent...

0 Likes
Message 4 of 15

Kent1Cooper
Consultant
Consultant

@Kent1Cooper wrote:
.... you would need to let the Explode command be completed before moving on to the Speak part.

 

  ....  (command "_.explode")

  (while (> (getvar 'cmdactive) 0) (command pause))

  (setq ....


Come to think of it, since Explode in a (command) function can work with only one object at a time [unless you go through some hoops -- Search here for QAFLAGS], you could probably do it more simply:

 

(defun C:exx () (command "explode" pause)
(setq sapi ....

Kent Cooper, AIA
Message 5 of 15

DGCSCAD
Collaborator
Collaborator

My apologies for digging up an old thread...

 

I've used this for quite a while now, but I'm on a new system and I get a "Class not registered" error.

(vl-load-com)
(setq speak (vlax-create-object "Sapi.SpVoice.1"))
(vlax-invoke speak "Speak" "I am sorry Dave I can not allow you to do that" 0)
(vlax-release-object speak)

 

Sapi.SpVoice and Sapi.SpVoice.1 are both in the registry so I'm not sure whats going on.

 

Any ideas?

AutoCad 2018 (full)
Win 11 Pro
0 Likes
Message 6 of 15

pendean
Community Legend
Community Legend

@DGCSCAD wrote:

I've used this for quite a while now, but I'm on a new system and I get a "Class not registered error".

 


Share a full screenshot of that error the program it popped up in so we can all understand the context better please.

0 Likes
Message 7 of 15

DGCSCAD
Collaborator
Collaborator
(defun c:speak ( / speak)
(vl-load-com)
(setq speak (vlax-create-object "Sapi.SpVoice"))
(vlax-invoke speak "Speak" "I am sorry Dave I can not allow you to do that" 0)
(vlax-release-object speak)
)

 

Command: speak
; error: Class not registered
Command:

AutoCad 2018 (full)
Win 11 Pro
0 Likes
Message 8 of 15

Sea-Haven
Mentor
Mentor

Maybe some extra switches.

 

(defun SpeakSapi ( s / sapi )
(if (eq (type s) 'STR) 
(progn 
(setq sapi (vlax-create-object "Sapi.SpVoice"))
(vlax-put sapi 'SynchronousSpeakTimeout 1)
(vlax-invoke-method sapi 'WaitUntilDone 0)
(vlax-invoke sapi "Speak" s 0)
(vlax-release-object sapi)
)))
(speaksapi "Happy Birthday from AL thank you for your on-going help")
0 Likes
Message 9 of 15

DGCSCAD
Collaborator
Collaborator

@Sea-Haven wrote:

Maybe some extra switches.

 

 

(defun SpeakSapi ( s / sapi )
(if (eq (type s) 'STR) 
(progn 
(setq sapi (vlax-create-object "Sapi.SpVoice"))
(vlax-put sapi 'SynchronousSpeakTimeout 1)
(vlax-invoke-method sapi 'WaitUntilDone 0)
(vlax-invoke sapi "Speak" s 0)
(vlax-release-object sapi)
)))
(speaksapi "Happy Birthday from AL thank you for your on-going help")

 


I appreciate the help. Still getting the error tho.

 

Command: (load"speak")
SPEAKSAPI
Command: (speaksapi "Happy Birthday from AL thank you for your on-going help")
Error: Class not registered
bad argument type: VLA-OBJECT nil

 

I even threw a (vl-load-com) in there to make sure.

AutoCad 2018 (full)
Win 11 Pro
0 Likes
Message 10 of 15

pendean
Community Legend
Community Legend

@DGCSCAD wrote:

Command: (load"speak")
SPEAKSAPI
Command: (speaksapi "Happy Birthday from AL thank you for your on-going help")
Error: Class not registered
bad argument type: VLA-OBJECT nil

Confirm you are NOT using the LT versions of AutoCAD please (2024/2025).

0 Likes
Message 11 of 15

DGCSCAD
Collaborator
Collaborator

@pendean wrote:

@DGCSCAD wrote:

Command: (load"speak")
SPEAKSAPI
Command: (speaksapi "Happy Birthday from AL thank you for your on-going help")
Error: Class not registered
bad argument type: VLA-OBJECT nil

Confirm you are NOT using the LT versions of AutoCAD please (2024/2025).


My apologies, here's my setup:

AutoCad 2018 (full)

Win 10 Pro

 

AutoCad 2018 (full)
Win 11 Pro
0 Likes
Message 12 of 15

Sea-Haven
Mentor
Mentor
(setq sapi (vlax-create-object "Sapi.SpVoice"))
#<VLA-OBJECT ISpeechVoice 0000000023C93880>
: (setq s "test message")
"test message"
: (vlax-invoke sapi "Speak" s 0)
1
Message was heard.

Pretty sure worked with 2018. 

Do the following and copy 1  at a time to command line

(setq sapi (vlax-create-object "Sapi.SpVoice"))

 

if no error message 

(setq s "Test message")

 

(vlax-invoke sapi "Speak" s 0)

 

let us know where error occurs.

 

0 Likes
Message 13 of 15

vladimir_michl
Advisor
Advisor

Are you using some non-EN version of Windows? You may need to install the voice support for "non-standard" languages. Also make sure the SAPI.SpVoice support is properly registered - usually in this DLL:

%SystemRoot%\System32\Speech\Common\sapi.dll

(so perform a regsvr32 on it)

 

BTW, you can use the voice output even in AutoCAD LT - see https://www.cadforum.cz/en/workaround-for-the-missing-vlax-create-object-in-autocad-lt-tip14007

 

Vladimir Michl, www.arkance-systems.cz  -  www.cadforum.cz

 

0 Likes
Message 14 of 15

DGCSCAD
Collaborator
Collaborator

@Sea-Haven 

After restarting AutoCad and running each line of your post separately at the command line, it's working. Thank you for the nudge. It seems like lately I've been posting up questions to problems I'm having without fully exhausting all possibilities of what could be wrong. Thanks for bearing with me and taking the time to walk me through it. Some days I'm just "off" by about >< that much. lol

 

@vladimir_michl 

Good to know.

AutoCad 2018 (full)
Win 11 Pro
0 Likes
Message 15 of 15

Sea-Haven
Mentor
Mentor

Sometimes I find I have to close and restart CAD as it seems to get stuck in a loop and not update correctly particularly when repeatedly trying code. I do a lot of copy and paste when writing code and that may the problem.