From 7569e95f7da976c0494509318a86c3db378e4874 Mon Sep 17 00:00:00 2001 From: Shunichi Nozawa Date: Thu, 24 Nov 2016 10:50:05 +0900 Subject: [PATCH 1/3] [pr2eus/speak.l, test/speak-test.l] Add speak-en-jp to switch language by speak_language rosparam and add test codes --- pr2eus/speak.l | 35 +++++++++++++++++++++++++++++++++++ pr2eus/test/speak-test.l | 14 ++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/pr2eus/speak.l b/pr2eus/speak.l index a0aadc9b0..ce78e67a4 100644 --- a/pr2eus/speak.l +++ b/pr2eus/speak.l @@ -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 diff --git a/pr2eus/test/speak-test.l b/pr2eus/test/speak-test.l index b51aacbb1..30a79da10 100644 --- a/pr2eus/test/speak-test.l +++ b/pr2eus/test/speak-test.l @@ -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) From fdb5f9e7bb616eb3fe416f6d9cc660c39c7d7745 Mon Sep 17 00:00:00 2001 From: iory Date: Tue, 18 Dec 2018 13:04:59 +0900 Subject: [PATCH 2/3] [pr2eus/speak.l] Use google engine if we cannot find default voice engine. --- pr2eus/speak.l | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pr2eus/speak.l b/pr2eus/speak.l index ce78e67a4..dd6554c10 100644 --- a/pr2eus/speak.l +++ b/pr2eus/speak.l @@ -104,7 +104,8 @@ (setq speak-func #'speak-google)) ;; Check speak-xx function existence. (unless speak-func - (error ";; No such speak function (speak-~A) defined!!~%" lang)) + (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) From 83f812c81f155436cb35b55b648fe28954cfa4cd Mon Sep 17 00:00:00 2001 From: iory Date: Tue, 18 Dec 2018 13:22:17 +0900 Subject: [PATCH 3/3] [pr2eus/speak.l] Use intern to check function exists such that speak-en, speak-jp --- pr2eus/speak.l | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pr2eus/speak.l b/pr2eus/speak.l index dd6554c10..b1a417e67 100644 --- a/pr2eus/speak.l +++ b/pr2eus/speak.l @@ -95,8 +95,8 @@ (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)))))) + (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)