also looking at this
meemalabs/laravel-text-to-speech
Added support for speech marks.
#26
7 files
+125
-19
Review threads live on the whole diff, not on one commit, so none are shown here - a thread's line means something in the branch's final form, and painting it into an intermediate step would put it on code it is not about.
| @@ -82,6 +82,14 @@ return [ | ||
| 82 | 82 | */ |
| 83 | 83 | 'voice_id' => env('AWS_VOICE_ID', 'Amy'), |
| 84 | 84 | |
| 85 | /** | |
| 86 | * You can request any or all of the speech mark types, but leave it empty if you don't use speech marks. | |
| 87 | * You may add any of the following:. | |
| 88 | * | |
| 89 | * sentence, word, viseme, ssml | |
| 90 | */ | |
| 91 | 'speech_marks' => [], | |
| 92 | ||
| 85 | 93 | /** |
| 86 | 94 | * IAM Credentials from AWS. |
| 87 | 95 | */ |
| @@ -87,12 +87,14 @@ class PollyConverter implements Converter | ||
| 87 | 87 | */ |
| 88 | 88 | protected function synthesizeSpeech($text, array $options = null) |
| 89 | 89 | { |
| 90 | $speechMarks = $this->getSpeechMarks(); | |
| 91 | ||
| 90 | 92 | $arguments = [ |
| 91 | 93 | 'LanguageCode' => $this->getLanguage(), |
| 92 | 94 | 'VoiceId' => $this->voice($options), |
| 93 | 95 | 'OutputFormat' => $this->format($options), |
| 94 | 96 | 'TextType' => $this->textType(), |
| 95 | 'SpeechMarkTypes' => $this->speechMarks, | |
| 97 | 'SpeechMarkTypes' => $speechMarks, | |
| 96 | 98 | ]; |
| 97 | 99 | |
| 98 | 100 | if (is_string($text)) { |
| @@ -204,6 +206,18 @@ class PollyConverter implements Converter | ||
| 204 | 206 | return Arr::get($options, 'format', $default); |
| 205 | 207 | } |
| 206 | 208 | |
| 209 | /** | |
| 210 | * Get the speech marks. | |
| 211 | * | |
| 212 | * @return array | |
| 213 | */ | |
| 214 | protected function getSpeechMarks() | |
| 215 | { | |
| 216 | $default = config('tts.services.polly.speech_marks', []); | |
| 217 | ||
| 218 | return ! empty($this->speechMarks) ? $this->speechMarks : $default; | |
| 219 | } | |
| 220 | ||
| 207 | 221 | /** |
| 208 | 222 | * Get the content of the result from AWS Polly. |
| 209 | 223 | * |
| @@ -222,7 +236,7 @@ class PollyConverter implements Converter | ||
| 222 | 236 | */ |
| 223 | 237 | protected function hasSpeechMarks() |
| 224 | 238 | { |
| 225 | return ! empty($this->speechMarks); | |
| 239 | return ! empty($this->getSpeechMarks()); | |
| 226 | 240 | } |
| 227 | 241 | |
| 228 | 242 | /** |