Results 1 to 6 of 6

Thread: Does TTS support base64 encode?

  1. #1

    Question Does TTS support base64 encode?

    I try to save Chinese text in json by JSON.decode,but some words converted into \u003f.
    Such as "作者" become "\u003f者" in .json
    But JSON.decode works without error...
    So I was thinking Could base64 encode works for tts?
    Maybe base64 function Could fix this bug.
    Last edited by Pola; 12-10-2016 at 08:37 AM.

  2. #2
    OK.I tested the following code.
    local b='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/' -- You will need this for encoding/decoding
    -- encoding
    function enc(data)
        return ((data:gsub('.', function(x) 
            local r,b='',x:byte()
            for i=8,1,-1 do r=r..(b%2^i-b%2^(i-1)>0 and '1' or '0') end
            return r;
        end)..'0000'):gsub('%d%d%d?%d?%d?%d?', function(x)
            if (#x < 6) then return '' end
            local c=0
            for i=1,6 do c=c+(x:sub(i,i)=='1' and 2^(6-i) or 0) end
            return b:sub(c+1,c+1)
        end)..({ '', '==', '=' })[#data%3+1])
    -- decoding
    function dec(data)
        data = string.gsub(data, '[^'..b..'=]', '')
        return (data:gsub('.', function(x)
            if (x == '=') then return '' end
            local r,f='',(b:find(x)-1)
            for i=6,1,-1 do r=r..(f%2^i-f%2^(i-1)>0 and '1' or '0') end
            return r;
        end):gsub('%d%d%d?%d?%d?%d?%d?%d?', function(x)
            if (#x ~= 8) then return '' end
            local c=0
            for i=1,8 do c=c+(x:sub(i,i)=='1' and 2^(8-i) or 0) end
                return string.char(c)

    It's lua standard library's Base64 Encode and Decode function.
    The results were desperate,Encode function works for any characters include the Chinese,but Decode function garbled every chinese character.
    So the conclusion is TTS doesn't support any form of Chinese characters save with json/lua.
    But the standard notecard supports Chinese characters save to json and load them without garbled.That makes me confusing.

  3. #3
    Join Date
    Sep 2016
    Looks like a bug to me. Unrelated, but it would be nice if TTS supported some kind of localization, so that multiple languages could be added to one workshop item.

  4. #4
    Why is this marked as Added?

  5. #5
    I picked the wrong prefix,and I can't change it...

  6. #6
    Quote Originally Posted by Pola View Post
    I picked the wrong prefix,and I can't change it...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts