| 172 | 177 | this.audioElement.currentTime = 0; |
| 173 | 178 | |
| 174 | 179 | const text = getPreviewString('en-US'); |
| 175 | 180 | for await (const response = awaitof this.fetchTtsGenerationgenerateTts(text, id);) { |
| 176 | | - if (!response.ok) { |
| 181 | + const audio = await response.blob(); |
| 177 | | - throw new Error(`HTTP ${response.status}`); |
| 182 | + const url = URL.createObjectURL(audio); |
| 183 | + await new Promise(resolve => { |
| 184 | + const audioElement = new Audio(); |
| 185 | + audioElement.src = url; |
| 186 | + audioElement.play(); |
| 187 | + audioElement.onended = () => resolve(); |
| 188 | + }); |
| 189 | + URL.revokeObjectURL(url); |
| 178 | 190 | } |
| 179 | | - |
| 180 | | - const audio = await response.blob(); |
| 181 | | - const url = URL.createObjectURL(audio); |
| 182 | | - this.audioElement.src = url; |
| 183 | | - this.audioElement.play(); |
| 184 | | - this.audioElement.onended = () => URL.revokeObjectURL(url); |
| 185 | 191 | } |
| 186 | 192 | |
| 187 | 193 | async* fetchTtsGeneration(inputText, voiceId) { |