调用百度API,HTML在线文字转语音播报

DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Documenttitle>

    <script>
        function doTTS() {
            var ttsDiv = document.getElementById('bdtts_div_id');
            var ttsAudio = document.getElementById('tts_autio_id');
            var ttsText = document.getElementById('ttsText').value;

            // 文字转语音
            ttsDiv.removeChild(ttsAudio);
            var au1 = '';
            var sss = '' + ttsText + '" type="audio/mpeg">';
            var eee = '';
            var au2 = '';
            ttsDiv.innerHTML = au1 + sss + eee + au2;

            ttsAudio = document.getElementById('tts_autio_id');

            ttsAudio.play();
        }
    script>
head>

<body>
    <div>
        <input type="text" id="ttsText" />
        <input type="button" id="tts_btn" onclick="doTTS()" value="播放" />
    div>
    <div id="bdtts_div_id">
        <audio id="tts_autio_id" autoplay="autoplay">
          <source id="tts_source_id" src="http://tts.baidu.com/text2audio?lan=zh&ie=UTF-8&spd=5&per=1&text=请输入文字" type="audio/mpeg">
          <embed id="tts_embed_id" height="0" width="0" src="">
        audio>
    div>
body>

html>

 

你可能感兴趣的:(调用百度API,HTML在线文字转语音播报)