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

Add speak-en-jp to switch language by speak_language rosparam and add test codes. #263

Closed
wants to merge 1 commit into from
Closed
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
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=)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for me, using intern seems suitable for this case.

12.eusgl$ (functionp (intern "SPEAK-JP"))
t
13.eusgl$ (functionp (intern "SPEAK-CN"))
nil
14.eusgl$ (functionp (intern "SPEAK-EN"))
t

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is reflected on #383

(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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you can not find speak-func, use google, this is why we choose "en" instead of "english"

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is reflected on #383

(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)