Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | 1x | import {Predictions} from "@aws-amplify/predictions";
import type {VoiceId} from "@aws-sdk/client-polly";
export async function textToSpeech(text: string, voice: VoiceId): Promise<HTMLAudioElement> {
const speech = await Predictions.convert({
textToSpeech: {
source: {
text: text,
},
voiceId: voice,
},
});
const audioStream = speech.audioStream;
const audioBlob = new Blob([audioStream], {
type: "audio/mp3",
});
const audioURL = URL.createObjectURL(audioBlob);
const audio = new Audio(audioURL);
await audio.play();
return audio;
}
|