{"id":1189,"date":"2024-09-12T16:36:58","date_gmt":"2024-09-12T08:36:58","guid":{"rendered":"https:\/\/crazylab.cloud\/crazylab\/?page_id=1189"},"modified":"2024-09-12T16:36:58","modified_gmt":"2024-09-12T08:36:58","slug":"display-photos-with-tts","status":"publish","type":"page","link":"https:\/\/crazylab.cloud\/crazylab\/?page_id=1189","title":{"rendered":"Display photos with tts"},"content":{"rendered":"\n    <style>\n        #display-photos-container {\n            position: relative;\n            width: 100%;\n            height: 100vh;\n            background-size: contain; \/* \u8abf\u6574\u80cc\u666f\u5716\u7247\u5927\u5c0f\u53ca\u4f4d\u7f6e\u6a23\u5f0f *\/\n            background-position: center;\n            background-repeat: no-repeat;\n        }\n    <\/style>\n    <div id=\"display-photos-container\"><\/div>\n    <script>\n        document.addEventListener(\"DOMContentLoaded\", function() {\n            window.photoContainer = document.getElementById('display-photos-container');\n\n            \/\/ \u5b9a\u7fa9\u5168\u5c40\u51fd\u6578\u4ee5\u986f\u793a\u5716\u7247\u4e26\u64ad\u653e TTS\n            window.displayPhotoAndSpeak = function(photoUrl, text, lang) {\n                return new Promise(function(resolve) {\n                    \/\/ \u986f\u793a\u5716\u7247\n                    if (window.photoContainer) {\n                        window.photoContainer.style.backgroundImage = 'url(' + photoUrl + ')';\n                    } else {\n                        console.error(\"Photo container not found.\");\n                    }\n                    \n                    \/\/ \u64ad\u653e TTS \u8a9e\u97f3\n                    var utterance = new SpeechSynthesisUtterance(text);\n                    utterance.lang = lang;\n                    utterance.onend = resolve;\n                    speechSynthesis.speak(utterance);\n                });\n            };\n\n            \/\/ \u6309\u9806\u5e8f\u986f\u793a\u5716\u7247\u548c\u6717\u8b80\u6587\u5b57\n            async function runSequence() {\n                while (true) {\n                    await window.displayPhotoAndSpeak(\"\", \"\", \"\");\n                    await new Promise(resolve => setTimeout(resolve, 10000)); \/\/ \u7b49\u5f85 10 \u79d2\n\n                    await window.displayPhotoAndSpeak(\"\", \"\", \"\");\n                    await new Promise(resolve => setTimeout(resolve, 10000)); \/\/ \u7b49\u5f85 10 \u79d2\n\n                    await window.displayPhotoAndSpeak(\"\", \"\", \"\");\n                    await new Promise(resolve => setTimeout(resolve, 10000)); \/\/ \u7b49\u5f85 10 \u79d2\n                }\n            }\n\n            \/\/ \u78ba\u4fdd\u8a9e\u97f3\u5408\u6210\u5c31\u7dd2\u5f8c\u958b\u59cb\u57f7\u884c\u5faa\u74b0\n            window.speechSynthesis.onvoiceschanged = runSequence;\n        });\n    <\/script>\n    \n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"h5ap_radio_sources":[],"footnotes":""},"class_list":["post-1189","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/crazylab.cloud\/crazylab\/index.php?rest_route=\/wp\/v2\/pages\/1189","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/crazylab.cloud\/crazylab\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/crazylab.cloud\/crazylab\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/crazylab.cloud\/crazylab\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/crazylab.cloud\/crazylab\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1189"}],"version-history":[{"count":1,"href":"https:\/\/crazylab.cloud\/crazylab\/index.php?rest_route=\/wp\/v2\/pages\/1189\/revisions"}],"predecessor-version":[{"id":1190,"href":"https:\/\/crazylab.cloud\/crazylab\/index.php?rest_route=\/wp\/v2\/pages\/1189\/revisions\/1190"}],"wp:attachment":[{"href":"https:\/\/crazylab.cloud\/crazylab\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1189"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}