<template>
<div>
<input v-model="textToSpeech" placeholder="输入文字">
<button @click="speak">语音播报</button>
</div>
</template>
<script>
export default {
data() {
return {
textToSpeech: '',
speech: null
};
},
methods: {
speak() {
if ('speechSynthesis' in window) {
this.speech = new SpeechSynthesisUtterance(this.textToSpeech);
this.speech.lang = 'zh-CN';
this.speech.rate = 1;
this.speech.pitch = 1;
this.speech.volume = 1;
window.speechSynthesis.speak(this.speech);
} else {
alert('您的浏览器不支持语音合成功能');
}
}
}
};
</script>