Remove accent if only one syllable in word.
--- a/contrib/gadict.el Wed Oct 04 21:22:27 2017 +0300
+++ b/contrib/gadict.el Wed Oct 04 21:46:37 2017 +0300
@@ -40,6 +40,25 @@
+(defconst gadict--vowels-re "[o$(O+8+:+7+9(Ba$(O+3+0,Af(Be,0#$(O+1(Bi,0!(Bu$(O+5+C+U+S+T(B]+")
+
+(defun gadict--vowel-group-count (s)
+ (let ( (cnt 0) (start 0) )
+ (while (string-match gadict--vowels-re s start)
+ (setq cnt (1+ cnt))
+ (setq start (match-end 0)))
+ cnt))
+
+(defun gadict--espeak-cleanup-accent (s)
+ "Remove accent if only one syllable in word."
+ (if (<= (gadict--vowel-group-count s) 1)
+ (replace-regexp-in-string "$,1$h(B" "" s)
+ s))
+
+(defun gadict--espeak-cleanup-accent-in-sentence (s)
+ "Remove accent if only one syllable in word."
+ (mapconcat #'gadict--espeak-cleanup-accent (split-string s " ") " "))
+
(defun gadict--espeak-cleanup (s)
"Cleanup espeak IPA output."
(mapc (lambda (fn) (setq s (funcall fn s)))
@@ -47,7 +66,8 @@
;; UTF symbol between t$(O*h(B to make ligature.
(lambda (str) (replace-regexp-in-string "[\x200D]" "" str))
(lambda (str) (replace-regexp-in-string "t$(O*h(B" "$,1$G(B" str))
- #'gadict--trim))
+ #'gadict--trim
+ #'gadict--espeak-cleanup-accent-in-sentence))
s)
(defvar gadict-espeak-enabled nil