oscie57 / tiktok-voice

Simple Python script to interact with the TikTok TTS API
515 stars 74 forks source link

Status error 1 - unable to find the cause #54

Open aaa3334 opened 3 months ago

aaa3334 commented 3 months ago

Is anyone currently using it? I have been getting status error 1. When looking at the error page it says it could be because the params are wrong.. but they seem to be correct here. Any ideas?

Note this is the request url and this is the response I get

https://api16-normal-useast5.us.tiktokv.com/media/api/text/speech/invoke/?text_speaker=en_us_002&req_text=Testing+text+here&speaker_map_type=0&aid=1233 {'status': 'Couldn’t load speech. Try again.', 'status_code': 1, 'status_msg': 'Couldn’t load speech. Try again.'}

(Have tried both of these base urls here: API_BASE_URL = f"https://api16-normal-v6.tiktokv.com/media/api/text/speech/invoke/" API_BASE_URL_2="https://api16-normal-useast5.us.tiktokv.com/media/api/text/speech/invoke/")

Note I did try to find a different base url incase that was the issue, but any I got an error when trying to request them, so I don't think its the base url here thats the issue... any ideas on what could be causing the error?

This is what https://github.com/oscie57/tiktok-voice/wiki/Status-Codes says: status_code: 1

Status Code 1 is caused by an incorrect aid value in the request parameters. The set value should be 1233.

There is another case with status code 1, where a parameter isn't passed, either text_speaker or req_text is missing.

But as you can see in the url's (?text_speaker=en_us_002&req_text=Testing+text+here&speaker_map_type=0&aid=1233), this does not seem to be the reason...

Note this is the top of my function (just edited slightly to stop status error 1 crashing it)

API_BASE_URL = f"https://api16-normal-v6.tiktokv.com/media/api/text/speech/invoke/" API_BASE_URL_2="https://api16-normal-useast5.us.tiktokv.com/media/api/text/speech/invoke/"

USER_AGENT = f"com.zhiliaoapp.musically/2022600030 (Linux; U; Android 7.1.2; es_ES; SM-G988N; Build/NRD90M;tt-ok/3.12.13.1)"

def tts(session_id: str, text_speaker: str = "en_us_002", req_text: str = "TikTok Text To Speech", filename: str = 'voice.mp3', play: bool = False):

req_text = req_text.replace("+", "plus")
req_text = req_text.replace(" ", "+")
req_text = req_text.replace("&", "and")
req_text = req_text.replace("ä", "ae")
req_text = req_text.replace("ö", "oe")
req_text = req_text.replace("ü", "ue")
req_text = req_text.replace("ß", "ss")

print(f"{API_BASE_URL}?text_speaker={text_speaker}&req_text={req_text}&speaker_map_type=0&aid=1233")
r = requests.post(
    f"{API_BASE_URL}?text_speaker={text_speaker}&req_text={req_text}&speaker_map_type=0&aid=1233",
    headers={
        'User-Agent': USER_AGENT,
        'Cookie': f'sessionid={session_id}'
    }
)

if r.json()["message"] == "Couldn't load speech. Try again.":
    output_data = {"status": "Session ID is invalid", "status_code": 5}
    print(output_data)
    return output_data

if r.json()["status_code"] == 1:
    output_data = {"status": r.json()["message"], "status_code": 1, "status_msg": r.json()["status_msg"]}
    print(output_data)
    return output_data

#print("The new data here is ", r.json())

vstr = [r.json()["data"]["v_str"]][0]
msg = [r.json()["message"]][0]
scode = [r.json()["status_code"]][0]
log = [r.json()["extra"]["log_id"]][0]

dur = [r.json()["data"]["duration"]][0]
spkr = [r.json()["data"]["speaker"]][0]
aaa3334 commented 3 months ago

Still having the same issue.. wondered if it was the sessionid but doesnt seem to make a difference when I refresh it with a new one.. (also it says here that should be error 5). Anyone having any difficulties or is it working for you? Note am based in australia and have tried multiple different possible api links I have found online - some give actual errors but the ones which seem to potentially be valid just send me a status 1 code..

ipharksai commented 2 months ago

same for me, aid value is wrong

aaa3334 commented 2 months ago

same for me, aid value is wrong

Did you find the right aid value?