Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add speak function to switch language by speak_language rosparam and add test codes. #383

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions pr2eus/speak.l
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,40 @@
: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
(when (functionp (intern (read-from-string (format nil "'speak-~A" lang))))
(intern (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
(warn ";; No such speak function (speak-~A) defined!! Using google engine~%" lang)
(setq speak-func #'speak-google))
(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)