{"id":5828,"date":"2024-04-24T19:54:26","date_gmt":"2024-04-24T16:54:26","guid":{"rendered":"https:\/\/unitycoder.com\/blog\/?p=5828"},"modified":"2024-04-24T19:54:55","modified_gmt":"2024-04-24T16:54:55","slug":"use-tiktok-tts-in-unity-with-webrequest","status":"publish","type":"post","link":"https:\/\/unitycoder.com\/blog\/2024\/04\/24\/use-tiktok-tts-in-unity-with-webrequest\/","title":{"rendered":"Use TikTok-TTS in Unity (with WebRequest)"},"content":{"rendered":"\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2024\/04\/image.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"482\" height=\"350\" data-attachment-id=\"5836\" data-permalink=\"https:\/\/unitycoder.com\/blog\/2024\/04\/24\/use-tiktok-tts-in-unity-with-webrequest\/image-41\/\" data-orig-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2024\/04\/image.png?fit=482%2C350&amp;ssl=1\" data-orig-size=\"482,350\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"image\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2024\/04\/image.png?fit=300%2C218&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2024\/04\/image.png?fit=482%2C350&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2024\/04\/image.png?resize=482%2C350&#038;ssl=1\" alt=\"\" class=\"wp-image-5836\" srcset=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2024\/04\/image.png?w=482&amp;ssl=1 482w, https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2024\/04\/image.png?resize=300%2C218&amp;ssl=1 300w\" sizes=\"auto, (max-width: 482px) 100vw, 482px\" \/><\/a><\/figure>\n\n\n\n<p>Was watching some weird physics based game developed at <a href=\"https:\/\/www.twitch.tv\/clayman_dev\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/www.twitch.tv\/clayman_dev<\/a> and they used node.js+tiktok TTS to play funny text-to-speech sounds!<br><br>Then found this library, <a href=\"https:\/\/github.com\/Steve0929\/tiktok-tts\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/github.com\/Steve0929\/tiktok-tts<\/a> <br>(took a while to get it working as node.js, due to sessionid+server mismatch, but posted solution here <a href=\"https:\/\/github.com\/Steve0929\/tiktok-tts\/issues\/17\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/github.com\/Steve0929\/tiktok-tts\/issues\/17<\/a> )<br><br>Then &#8220;converted&#8221; it to Unity.. (*not much to convert, it is just a Webrequest (POST) and few header values.. problem is that if you post wrong data, it just says &#8220;404&#8221;, so you don&#8217;t know whats the issue..<br><br>Initially tried to get this working <a href=\"https:\/\/docs.unity3d.com\/ScriptReference\/Networking.UnityWebRequestMultimedia.GetAudioClip.html\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/docs.unity3d.com\/ScriptReference\/Networking.UnityWebRequestMultimedia.GetAudioClip.html<\/a> but then checked original node.js sources, where it uses POST request, instead of GET.. so that was the main issue! (and setting cookie to getrequest was probably initially wrong, <br><br><strong>Check repo source &amp; instructions for getting tiktok sessionid+server:<\/strong><br><a href=\"https:\/\/github.com\/unitycoder\/tiktok-tts-unity\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/github.com\/unitycoder\/tiktok-tts-unity<\/a><\/p>\n\n\n\n<p><strong>Sample audio:<\/strong><br><a href=\"https:\/\/soundcloud.com\/user-689598301\/tiktok-tts-sample\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/soundcloud.com\/user-689598301\/tiktok-tts-sample<\/a><\/p>\n\n\n\n<p><strong>making of \/ struggling video:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<span class=\"embed-youtube\" style=\"text-align:center; display: block;\"><iframe loading=\"lazy\" class=\"youtube-player\" width=\"640\" height=\"360\" src=\"https:\/\/www.youtube.com\/embed\/yaA9XV_WY78?version=3&#038;rel=1&#038;showsearch=0&#038;showinfo=1&#038;iv_load_policy=1&#038;fs=1&#038;hl=en-US&#038;autohide=2&#038;wmode=transparent\" allowfullscreen=\"true\" style=\"border:0;\" sandbox=\"allow-scripts allow-same-origin allow-popups allow-presentation allow-popups-to-escape-sandbox\"><\/iframe><\/span>\n<\/div><\/figure>\n\n\n\n<p><br>*This is not their official API, so it could be closed anytime or the servers might change..<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Was watching some weird physics based game developed at https:\/\/www.twitch.tv\/clayman_dev and they used node.js+tiktok TTS to play funny text-to-speech sounds! Then found this library, https:\/\/github.com\/Steve0929\/tiktok-tts (took a while to get it working as node.js, due to sessionid+server mismatch, but posted solution here https:\/\/github.com\/Steve0929\/tiktok-tts\/issues\/17 ) Then [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":5836,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":false,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[1056,1,3],"tags":[1286,1139],"class_list":["post-5828","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-external-tools","category-uncategorized","category-unity3d","tag-text-to-speech","tag-tts"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2024\/04\/image.png?fit=482%2C350&ssl=1","jetpack_shortlink":"https:\/\/wp.me\/p1KTaT-1w0","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/posts\/5828","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/comments?post=5828"}],"version-history":[{"count":10,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/posts\/5828\/revisions"}],"predecessor-version":[{"id":5839,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/posts\/5828\/revisions\/5839"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/media\/5836"}],"wp:attachment":[{"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/media?parent=5828"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/categories?post=5828"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/tags?post=5828"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}