also looking at this
meemalabs/laravel-text-to-speech
Apply fixes from StyleCI
#11
2 files
+12
-18
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.
| @@ -51,15 +51,13 @@ class PollyConverter implements Converter | ||
| 51 | 51 | { |
| 52 | 52 | $text = $this->getTextFromSource($data); |
| 53 | 53 | |
| 54 | if ($this->isTextAboveLimit($text)) | |
| 55 | { | |
| 54 | if ($this->isTextAboveLimit($text)) { | |
| 56 | 55 | $text = $this->getChunkText($text); |
| 57 | 56 | } |
| 58 | 57 | |
| 59 | 58 | $result = $this->synthesizeSpeech($text, $options); |
| 60 | 59 | |
| 61 | if ($result instanceof Result) | |
| 62 | { | |
| 60 | if ($result instanceof Result) { | |
| 63 | 61 | // Store audio file to disk |
| 64 | 62 | return $this->store( |
| 65 | 63 | $this->getTextFromSource($data), |
| @@ -71,7 +69,6 @@ class PollyConverter implements Converter formatting only | ||
| 71 | 69 | $this->getTextFromSource($data), |
| 72 | 70 | $this->mergeOutputs($result) |
| 73 | 71 | ); |
| 74 | ||
| 75 | 72 | } |
| 76 | 73 | |
| 77 | 74 | /** |
| @@ -83,20 +80,18 @@ class PollyConverter implements Converter | ||
| 83 | 80 | */ |
| 84 | 81 | protected function synthesizeSpeech($text, array $options = null) |
| 85 | 82 | { |
| 86 | if (is_string($text)) | |
| 87 | { | |
| 83 | if (is_string($text)) { | |
| 88 | 84 | return $this->client->synthesizeSpeech([ |
| 89 | 85 | 'VoiceId' => $this->voice($options), |
| 90 | 86 | 'OutputFormat' => $this->format($options), |
| 91 | 87 | 'TextType' => 'ssml', |
| 92 | 'Text' => '<speak>' . $text . '</speak>', | |
| 88 | 'Text' => '<speak>'.$text.'</speak>', | |
| 93 | 89 | ]); |
| 94 | 90 | } |
| 95 | 91 | |
| 96 | 92 | $results = []; |
| 97 | 93 | |
| 98 | foreach ($text as $item) | |
| 99 | { | |
| 94 | foreach ($text as $item) { | |
| 100 | 95 | $result = $this->client->synthesizeSpeech([ |
| 101 | 96 | 'VoiceId' => $this->voice($options), |
| 102 | 97 | 'OutputFormat' => $this->format($options), |
| @@ -110,15 +105,14 @@ class PollyConverter implements Converter | ||
| 110 | 105 | } |
| 111 | 106 | |
| 112 | 107 | /** |
| 113 | * Merges the output from amazon polly | |
| 108 | * Merges the output from amazon polly. | |
| 114 | 109 | * |
| 115 | 110 | * @return mixed |
| 116 | 111 | */ |
| 117 | 112 | protected function mergeOutputs(array $results) |
| 118 | 113 | { |
| 119 | 114 | $mergedResult = null; |
| 120 | foreach ($results as $result) | |
| 121 | { | |
| 115 | foreach ($results as $result) { | |
| 122 | 116 | $mergedResult .= $this->getResultContent($result); |
| 123 | 117 | } |
| 124 | 118 | |
| @@ -126,10 +120,10 @@ class PollyConverter implements Converter | ||
| 126 | 120 | } |
| 127 | 121 | |
| 128 | 122 | /** |
| 129 | * Checks the length of the text if more than 3000 | |
| 123 | * Checks the length of the text if more than 3000. | |
| 130 | 124 | * |
| 131 | 125 | * @param string $text |
| 132 | * @return boolean | |
| 126 | * @return bool | |
| 133 | 127 | */ |
| 134 | 128 | protected function isTextAboveLimit(string $text) |
| 135 | 129 | { |
| @@ -137,7 +131,7 @@ class PollyConverter implements Converter | ||
| 137 | 131 | } |
| 138 | 132 | |
| 139 | 133 | /** |
| 140 | * Chunk the given text into array | |
| 134 | * Chunk the given text into array. | |
| 141 | 135 | * |
| 142 | 136 | * @param string $text |
| 143 | 137 | * @param int $size |
| @@ -145,7 +139,7 @@ class PollyConverter implements Converter formatting only | ||
| 145 | 139 | */ |
| 146 | 140 | protected function getChunkText(string $text, int $size = 2000) |
| 147 | 141 | { |
| 148 | return explode( "\n", wordwrap($text, $size)); | |
| 142 | return explode("\n", wordwrap($text, $size)); | |
| 149 | 143 | } |
| 150 | 144 | |
| 151 | 145 | /** |