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 7569e95
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
35 changes: 35 additions & 0 deletions pr2eus/speak.l
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,39 @@
:wait wait
:timeout timeout))

(defun speak
(speach-string-candidates
&rest args)
"Speak with language selection.
Argument:
speach-string-candidates should be two types:
List of cons of language name and speak-string. For example, '( (\"en\" . \"Hello\") (\"jp\" . \"こんにちわ\") )
English speak-string. For example, \"Hello\", which is same as '( (\"en\" . \"Hello\") ).
If adequate argument are not specified, english string are input to speak-google.
Speak language name:
Speak language name is switched by 'speak_language' rosparam.
If no such rosparam is specified, speak \"en\".
If users do not use speak-google, speak_language should be related with speak-xx functinos, such as speak-jp and speak-en. Otherwise, speak function invokes error."
;; Convert atom argument to candidate list
(if (stringp speach-string-candidates)
(setq speach-string-candidates (list (cons "en" speach-string-candidates))))
;; Check speak_language
(let* ((lang (or (ros::get-param "speak_language") "en"))
(speak-string (cdr (assoc lang speach-string-candidates :test #'string=)))
(speak-func
(if (fboundp (eval (read-from-string (format nil "'speak-~A" lang))))
(eval (read-from-string (format nil "#'speak-~A" lang))))))
;; Check argument
(unless speak-string
(warn ";; No speach string are specified for ~A from argumenta!! Use english and speak-google!!~%" lang)
(setq speak-string (cdr (assoc "en" speach-string-candidates :test #'string=)))
(setq speak-func #'speak-google))
;; Check speak-xx function existence.
(unless speak-func
(error ";; No such speak function (speak-~A) defined!!~%" lang))
(warn ";; ~A~%" (list (cadr speak-func) speak-string args))
;; Speak
(apply speak-func 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)
(speak "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)))
))

(run-all-tests)
(exit)

0 comments on commit 7569e95

Please sign in to comment.