diff --git a/config/config.php b/config/config.php index e264a27..12e679d 100644 --- a/config/config.php +++ b/config/config.php @@ -82,6 +82,14 @@ */ 'voice_id' => env('AWS_VOICE_ID', 'Amy'), + /** + * You can request any or all of the speech mark types, but leave it empty if you don't use speech marks. + * You may add any of the following:. + * + * sentence, word, viseme, ssml + */ + 'speech_marks' => [], + /** * IAM Credentials from AWS. */ diff --git a/src/Converters/PollyConverter.php b/src/Converters/PollyConverter.php index b787ea0..8faf49c 100644 --- a/src/Converters/PollyConverter.php +++ b/src/Converters/PollyConverter.php @@ -87,12 +87,14 @@ public function convert(string $data, array $options = null) */ protected function synthesizeSpeech($text, array $options = null) { + $speechMarks = $this->getSpeechMarks(); + $arguments = [ 'LanguageCode' => $this->getLanguage(), 'VoiceId' => $this->voice($options), 'OutputFormat' => $this->format($options), 'TextType' => $this->textType(), - 'SpeechMarkTypes' => $this->speechMarks, + 'SpeechMarkTypes' => $speechMarks, ]; if (is_string($text)) { @@ -204,6 +206,18 @@ protected function format($options) return Arr::get($options, 'format', $default); } + /** + * Get the speech marks. + * + * @return array + */ + protected function getSpeechMarks() + { + $default = config('tts.services.polly.speech_marks', []); + + return ! empty($this->speechMarks) ? $this->speechMarks : $default; + } + /** * Get the content of the result from AWS Polly. * @@ -222,7 +236,7 @@ protected function getResultContent($result) */ protected function hasSpeechMarks() { - return ! empty($this->speechMarks); + return ! empty($this->getSpeechMarks()); } /**