FastFiber

AutoCAD speak to me.

Gestart door HofCAD, ma 22 01 2007, 09:46:53

Vorige topic - Volgende topic

HofCAD

Beste CAD liefhebbers,

Op http://www.theswamp.org/index.php?topic=14549.0 heeft Patrick_35
een tip gegeven om AutoCAD te laten praten via Microsoft Speech.


(defun C:SpeakCfg(/ Sapi ~voice ~volume ~rate Voice VoiceMary VoiceMike
                   VoiceSam VoiceLst NumVoices @SendKeysN @PlayWav
                   @NoPath @VoiceList @member+ @Voice&TextInput)

;**********************SubPrograms************************************************
(defun @SendKeysN (Keys n / Wscript)
 (if (setq Wscript (vlax-create-object "WScript.Shell"))
   (progn (repeat n
      (vlax-invoke-method Wscript 'SendKeys Keys))
      (vlax-release-object Wscript)
   )
 )  
(princ)
)
(defun @PlayWav (Sapi WavFile / WavPath @@FindFile ObjFile)
(defun @@FindFile(WavFile / WinDir Path i DirLst)
(setq WinDir (getenv "Windir"))
(setq Path nil i 0 DirLst
(list "" "c:\\" (strcat WinDir "\\")
(strcat WinDir "\\media\\")
(strcat WinDir "\\System\\")
(strcat WinDir "\\System32\\")
(strcat WinDir "\\System64\\")
(strcat WinDir "\\System32\\drivers\\")))
(while (and (< i (length DirLst))
(= (setq Path (findfile (strcat (nth i DirLst) WavFile))) nil))
(setq i (1+ i)))
Path
)
(setq WavPath (@@FindFile WavFile))
(if (and WavPath Sapi)
(progn
(setq ObjFile (vlax-create-object "SAPI.SpFileStream.1"))
(vlax-invoke ObjFile "Open" WavPath)
(vlax-invoke Sapi "Speakstream" ObjFile 0)
(vlax-release-object ObjFile)
))
)
(defun @NoPath(s / cnt ct name)
(setq name (strcase s T))
(if (= (substr name 2 1) ":")
(setq name (substr name 3)))
(setq cnt 1 ct 0)
(repeat (strlen name)
(if (= (substr name cnt 1) "\\")
(setq ct cnt)
)
(setq cnt (1+ cnt))
)
(setq name (substr name (+ 1 ct) cnt))
)
(defun @VoiceList(Sapi / i VoiceLst Voices)
(setq Voices (vlax-invoke Sapi 'GetVoices))
(setq i 0 VoiceLst '())
(repeat (vla-get-count Voices)
(setq VoiceLst (append VoiceLst
(list (vlax-invoke (vla-item Voices i) 'GetDescription))))
(setq i (1+ i))
)
VoiceLst
)
(defun @member+ (x lst /)
(if (vl-member-if '(lambda (y) (wcmatch x y)) lst) x)
)
(defun @Voice&TextInput(voice text / SpeekContent)
(setq SpeekContent (strcat "<VOICE REQUIRED='NAME=" voice "'>" text "</VOICE>"))
)

;**********************Main Program***********************************************
(vl-load-com)
(setq Sapi (vlax-create-object "Sapi.SpVoice"))
(if (not Sapi)(progn
(load "AI_UTILS")(princ "\nWarning: For sound, first install Microsoft Speech SDK 5.1")
(ai_abort "Sapi.SpVoice" (strcat "Warning: No Speech Application Programming Interface"
" with Microsoft Speech" "\n or with the speech module in MS Office."
"\n Suggestion: Install Microsoft Speech SDK 5.1 from http://www.microsoft.com/downloads/"))
))
(setq ~voice (@NoPath (vlax-get-property (vlax-get-property Sapi 'voice) 'Id)))
(cond
((= ~voice "msmary") (setq Voice "Microsoft Mary"))
((= ~voice "msmike") (setq Voice "Microsoft Mike"))
((= ~voice "mssam") (setq Voice "Microsoft Sam"))
(t (setq Voice ~voice))
)
;The voice is normally in Microsoft Speech "Microsoft Mary",
;but in the speech module in MS Office it is "Microsoft Sam".
(@SendKeysN (chr 175) 50);Maximize Volume
(setq ~volume (vlax-get-property Sapi 'Volume))
(vlax-put-property Sapi 'Volume 100)
(@playwav Sapi "notify.wav")
(vlax-invoke Sapi "Speak" (strcat "This is " Voice " speaking in AutoCAD with Sapi.     "
"Sapi is short for Speech Application Programming Interface.     "
"You can also use Sapi for playing Wave soundfiles in AutoCAD.") 0)
(@playwav Sapi "Ringin.wav")
(vlax-put-property Sapi 'Volume 10)
(vlax-invoke Sapi "Speak" "Do you want AutoCAD to speak with a soft volume?" 0)
(vlax-put-property Sapi 'Volume 50)
(vlax-invoke Sapi "Speak" "Do you want AutoCAD to speak with a medium volume?" 0)
(vlax-put-property Sapi 'Volume 100)
(vlax-invoke Sapi "Speak" "Do you want AutoCAD to speak with a loud volume?" 0)
;(vlax-put-property Sapi 'Volume ~volume)
(setq ~rate (vlax-get-property Sapi 'Rate))
(vlax-put-property Sapi 'Rate -8)
(vlax-invoke Sapi "Speak" "Do you want AutoCAD to speak with a slow rate?" 0)
(vlax-put-property Sapi 'Rate 5)
(vlax-invoke Sapi "Speak" "Do you want AutoCAD to speak with a fast rate?" 0)
(vlax-put-property Sapi 'Rate 0)
(vlax-invoke Sapi "Speak" "Do you want AutoCAD to speak with a normal rate?" 0)
;(vlax-put-property Sapi 'Rate ~rate)
(vlax-invoke Sapi "Speak" "Question,         Can I also change the voice?" 0)
(setq VoiceLst (@VoiceList Sapi))
;Gives normally with Microsoft Speech:("Microsoft Mary" "Microsoft Mike" "Microsoft Sam" "Sample TTS Voice")
;The voice "Sample TTS Voice" is not usable in a Sapi object, it is for use in TTSapp.exe and TTSappVB.exe
;Gives normally with Microsoft Office speech module:("Microsoft Sam")
(setq NumVoices(length VoiceLst))
(if (@member+ "Sample TTS Voice" VoiceLst) (setq NumVoices (1- NumVoices)))
(if (> NumVoices 1)
(vlax-invoke Sapi "Speak" (strcat "Yes. We can do this, because there are "
(itoa NumVoices) " usable voices on this system.") 0)
(progn
(vlax-invoke Sapi "Speak" (strcat "No. We can't do this, because there is only one voice on this system.  "
"  Probably, only the speech module of Microsoft Office is installed.") 0)
(princ (strcat "\nWarning: For more voices, first install Microsoft Speech SDK 5.1"
"\nfrom http://www.microsoft.com/downloads/"))))
(if (@member+ "Microsoft Mary" VoiceLst) (setq VoiceMary "Microsoft Mary"))
(if (@member+ "Microsoft Mike" VoiceLst) (setq VoiceMike "Microsoft Mike"))
(if (@member+ "Microsoft Sam" VoiceLst) (setq VoiceSam "Microsoft Sam"))
(if (and VoiceMary VoiceMike VoiceSam)
(progn
(vlax-invoke Sapi "Speak" (@Voice&TextInput VoiceMike
"My name is Microsoft Mike, and I have a question for Sam.") 0)
(vlax-invoke Sapi "Speak" (@Voice&TextInput VoiceMike
"Sam, could you say something about Mary?") 0)
(vlax-invoke Sapi "Speak" (@Voice&TextInput VoiceSam
"My name is Microsoft Sam, and I can say that Mary has a little lamb.") 0)
(vlax-invoke Sapi "Speak" (@Voice&TextInput VoiceMary
"Hi, this is Microsoft Mary and I think that Sam is joking like Mister Thomas Edison.") 0)
(vlax-invoke Sapi "Speak" (@Voice&TextInput VoiceMike
"This information is very interesting, and I would like to thank you all.") 0)
)
(progn
(vlax-invoke Sapi "Speak" "Warning      " 0)
(if (not VoiceMary) (vlax-invoke Sapi "Speak" "There is no Microsoft Mary." 0))
(if (not VoiceMike) (vlax-invoke Sapi "Speak" "There is no Microsoft Mike." 0))
(if (not VoiceSam) (vlax-invoke Sapi "Speak" "There is no Microsoft Sam." 0))
))
(@playwav Sapi "tada.wav")
(vlax-release-object sapi)
(princ)
)
(princ "SpeakCfg.lsp Loaded. \nRun with SPEAKCFG.")


Met vriendelijke groet,
Hofcad CSI

PS Het programma SpeakCfg gebruikt de Speech Application Programming Interface
van Microsoft Speech SDK 5.1 (http://www.microsoft.com/downloads/") of de
speech module van Microsoft Office (Microsoft Word 2002, or Microsoft Excel 2002).

Voor VBA versie zie http://www.cadsite.be/smf/index.php?topic=3653.msg18670#msg18670

ACADcadabra

julien

Nu nog een geluidskaart in mijn PC'tje steken en we kunnen dit testen.  :mrgreen:

HofCAD

Beste CAD liefhebbers,

Ik heb bovenstaand programma veranderd,
daar ik wilde tonen hoe je de stem kan veranderen.

Met vriendelijke groet,
Hofcad CSI
ACADcadabra

HofCAD

#3
Beste CAD liefhebbers,

Ik heb bovenstaand programma SpeakCfg.lsp veranderd,
daar ik het geluidsvolume op maximaal wil zetten.
Mijn vraag is nu, werkt mijn SendKey ook bij Windows Vista?
(defun SendKeysN(Keys n / Wscript)
(vl-load-com)
 (if (setq Wscript (vlax-create-object "WScript.Shell"))
   (progn (repeat n
      (vlax-invoke-method Wscript 'SendKeys Keys))
      (vlax-release-object Wscript)
   )
 )  
(princ)
)
(defun c:MaxVolume() ;For raise the volume
(SendKeysN (chr 175) 50)
)


Met vriendelijke groet,
Hofcad CSI
ACADcadabra

Kenny H

Hey HofCAD,

het lukt ook in vista om het volume maximaal te zetten!

Kenny
8) Volvo 4 Life 8)

HofCAD

Citaat van: Kenny H op wo 28 10 2009, 20:30:03
Hey HofCAD,

het lukt ook in vista om het volume maximaal te zetten!

Kenny
Beste Kenny,

Thanks.
Weet je soms ook een manier, hoe je controleren of Mute aan of uit staat?

Met vriendelijke groet, HofCAD CSI.
ACADcadabra