Skip to content

Commit

Permalink
[pr2eus/speak.l, test/speak-test.l] Add speak-en-jp to switch languag…
Browse files Browse the repository at this point in the history
…e by speak_language rosparam and add test codes
  • Loading branch information
snozawa committed Nov 24, 2016
1 parent 8538422 commit 7e2a735
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
27 changes: 27 additions & 0 deletions pr2eus/speak.l
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,31 @@
:wait wait
:timeout timeout))

(defun speak
(speach-string-candidates
&rest args)
"Speak with language selection.
Speak language name:
Speak language name is switched by 'speak_language' rosparam.
If no such rosparam is specified, speak \"en\".
speak_language should be related with speak-xx functinos, such as speak-jp and speak-en. Otherwise, speak function invokes error.
Argument:
speach-string-candidates argument is list of cons of language name and speak-string.
For example, '( (\"en\" . \"Hello\") (\"jp\" . \"こんにちわ\") )
If adequate argument are not specified, english string are selected."
(let* ((lang (or (ros::get-param "speak_language") "en"))
(speak-string (cdr (assoc lang speach-string-candidates :test #'string=))))
;; Check argument
(unless speak-string
(warn ";; No speach string are specified for ~A from argumenta!! Use en string!!~%" lang)
(setq lang "en")
(setq speak-string (cdr (assoc lang speach-string-candidates :test #'string=))))
;; Check speak-xx function existence.
(let ((speak-func (eval (read-from-string (format nil "'speak-~A" lang)))))
(unless (fboundp speak-func)
(error ";; No such speak function (speak-~A) defined!!~%" lang))
;;(warn ";; ~A~%" (list speak-func speak-string args))
(apply (eval (read-from-string (format nil "#'speak-~A" lang))) speak-string args)
)))

(provide :speak) ;; end of speak.l
14 changes: 14 additions & 0 deletions pr2eus/test/speak-test.l
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,20 @@
(deftest test-speak-google ()
(assert (speak-google "bonjour" :timeout 10 :lang :fr)))

(deftest test-speak-en-jp ()
(labels ((test-speak
()
(and (speak '(("en" . "hello, world") ("jp" . "こんにちは")) :timeout 10)
;; (speak '(("en" . "hello, world") ("jp" . "こんにちは")) :wait t :debug t)
(speak '(("en" . "hello, world") ("jp" . "こんにちは")) :timeout 10 :google t)
(speak '(("en" . "hello, world")) :timeout 10)
)))
(assert (progn (test-speak)))
(assert (progn (ros::set-param "speak_language" "jp") (test-speak)))
(assert (progn (ros::set-param "speak_language" "en") (test-speak)))
(assert (progn (ros::set-param "speak_language" "en") (test-speak)))
))

(run-all-tests)
(exit)

0 comments on commit 7e2a735

Please sign in to comment.