Uncaught TypeError: Cannot read property 'Synthesize' of undefined at hello.html:4
こういうエラーが出て、TTSを利用できません。
エラーの対処法回答よろしくお願いします。
html
1<script> 2var tts; 3tts.Synthesize(); 4 5var request = require('request'), 6 xmlbuilder = require('xmlbuilder'), 7 wav = require('wav'), 8 Speaker = require('speaker'); 9 10exports.Synthesize = function Synthesize(){ 11 12 // Note: The way to get api key: 13 // Free: https://www.microsoft.com/cognitive-services/en-us/subscriptions?productId=/products/Bing.Speech.Preview 14 // Paid: https://portal.azure.com/#create/Microsoft.CognitiveServices/apitype/Bing.Speech/pricingtier/S0 15 var apiKey = "キー入力済み"; 16 var ssml_doc = xmlbuilder.create('speak') 17 .att('version', '1.0') 18 .att('xml:lang', 'en-us') 19 .ele('voice') 20 .att('xml:lang', 'en-us') 21 .att('xml:gender', 'Female') 22 .att('name', 'Microsoft Server Speech Text to Speech Voice (en-US, ZiraRUS)') 23 .txt('This is a demo to call Microsoft text to speech service.') 24 .end(); 25 var post_speak_data = ssml_doc.toString(); 26 27 request.post({ 28 url: 'https://api.cognitive.microsoft.com/sts/v1.0/issueToken', 29 headers: { 30 'Ocp-Apim-Subscription-Key' : apiKey 31 } 32 }, function (err, resp, access_token) { 33 if (err || resp.statusCode != 200) { 34 console.log(err, resp.body); 35 } else { 36 try { 37 request.post({ 38 url: 'https://speech.platform.bing.com/synthesize', 39 body: post_speak_data, 40 headers: { 41 'content-type' : 'application/ssml+xml', 42 'X-Microsoft-OutputFormat' : 'riff-16khz-16bit-mono-pcm', 43 'Authorization': 'Bearer ' + access_token, 44 'X-Search-AppId': '07D3234E49CE426DAA29772419F436CA', 45 'X-Search-ClientID': '1ECFAE91408841A480F00935DC390960', 46 'User-Agent': 'TTSNodeJS' 47 }, 48 encoding: null 49 }, function (err, resp, speak_data) { 50 if (err || resp.statusCode != 200) { 51 console.log(err, resp.body); 52 } else { 53 try { 54 var reader = new wav.Reader(); 55 reader.on('format', function (format) { 56 reader.pipe(new Speaker(format)); 57 }); 58 var Readable = require('stream').Readable; 59 var s = new Readable; 60 s.push(speak_data); 61 s.push(null); 62 s.pipe(reader); 63 } catch (e) { 64 console.log(e.message); 65 } 66 } 67 }); 68 } catch (e) { 69 console.log(e.message); 70 } 71 } 72 }); 73}; 74</script>
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。