Open MarcoLavoro opened 1 month ago
same
+1
from what i can tell you have to use a session_id that is tied to right endpoint
TikTok might have changed its API endpoint.
store-idc seems to be gone in the cookies so that may have something to do with it
hi , from yesterday I am unable to use the TTS api I also created a new project to test it from scratch and tried severla session id but I get always the same error.
this is the what the api returns:
{'extra': {'log_id': '20241026091223E487F29CC9323B16AF0B'}, 'message': 'Couldn’t load speech. Try again.', 'status_code': 1, 'status_msg': 'Couldn’t load speech. Try again.'}
this is how I execute it
py main.py -v en_us_ghostface -f FILENAME.txt --session
this is the code:
`import requests, base64, random, argparse, os, playsound, time, re, textwrap from constants import voices
API_BASE_URL = f"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")
def batch_create(filename: str = 'voice.mp3'): out = open(filename, 'wb')
def main(): parser = argparse.ArgumentParser(description="Simple Python script to interact with the TikTok TTS API") parser.add_argument("-v", "--voice", help="the code of the desired voice") parser.add_argument("-t", "--text", help="the text to be read") parser.add_argument("-s", "--session", help="account session id") parser.add_argument("-f", "--file", help="use this if you wanna use 'text.txt'") parser.add_argument("-n", "--name", help="The name for the output file (.mp3)") parser.add_argument("-p", "--play", action='store_true', help="use this if you want to play your output") args = parser.parse_args()
def randomvoice(): count = random.randint(0, len(voices)) text_speaker = voices[count]
def sampler(): for item in voices: text_speaker = item filename = item print(item) req_text = 'TikTok Text To Speech Sample' tts(text_speaker, req_text, filename)
if name == "main": main() `