var button = document.getElementById( 'previewButton' ); button.disabled = true; var ctx = new AudioContext(); fetch( '/api/ra', { method: 'post', headers: headers, body: ssml } ).then( response => { if ( response.status == 200 ) { return response.arrayBuffer() } else if ( response.status == 401 ) { throw '无效的密钥'; } else { return response.text().then( text => Promise.reject( text ) ); } } ).then( arrayBuffer => ctx.decodeAudioData( arrayBuffer ) ) .then( audio => { var player = ctx.createBufferSource(); player.buffer = audio; player.connect( ctx.destination ); player.start( ctx.currentTime ); } ) .catch( reason => { alert( reason ); } ) .finally( () => { button.disabled = false; } ); } function createLegadoUrl () { var name = document.getElementsByName( 'name' )[ 0 ].value; var customVoiceName = document.getElementsByName( 'customVoiceName' )[ 0 ].value; var voiceName = customVoiceName != '' ? customVoiceName : document.getElementsByName( 'voiceName' )[ 0 ].value; var voiceFormat = document.getElementsByName( 'voiceFormat' )[ 0 ].value; var token = document.getElementsByName( 'token' )[ 0 ].value; var previewText = document.getElementsByName( 'previewText' )[ 0 ].value; var url = window.location.protocol + '//' + window.location.host + '/api/legado?api=' + encodeURI( window.location.protocol + '//' + window.location.host + '/api/ra' ) + '&name=' + encodeURI( name ) + '&voiceName=' + voiceName + '&voiceFormat=' + voiceFormat + '&token=' + token; var svg = new QRCode( url ).svg(); var modal = new bootstrap.Modal( document.getElementById( 'legadoUrlModal' ) ) modal.show(); document.getElementById( 'legadoUrlQRCode' ).innerHTML = svg; document.getElementById( 'legadoUrl' ).value = url; }