Extracting Transcriptions From TikTok
Video content has exploded in popularity, with short-form videos dominating social media platforms like TikTok. Traditional web scraping tools miss crucial context from these videos, as the spoken content often contains more valuable information than text descriptions. dScribe AI solves this problem by enabling developers to transcribe TikTok videos with just a URL.
Getting Started
Sign up for an account at dScribe AI and create an API key. For detailed setup instructions, check our Quickstart Guide.
Transcribing TikTok Videos with Python
dScribe AI's python package makes transcribing TikTok videos straightforward. To get started, first use pip to install the dscribeai
python packge:
pip install dscribeai
Now, all you need to do is import the dscribeai package, create a client, and call the transcribe
method with the TikTok URL you want to transcribe:
from dscribeai import DScribeAIClient
dscribeai = DScribeAIClient(api_key="<your_api_key>")
transcription_response = dscribeai.transcribe("https://www.tiktok.com/@microsoft/video/7489580646449417515")
# Print the transcription
print(transcription_response.data[0].transcription)
# Print the transcription with timestamps
for paragraph in transcription_response.data[0].paragraphs:
for sentence in paragraph.sentences:
print(f"{sentence.start}s - {sentence.end}s: {sentence.text}")
Using Callbacks for Asynchronous Processing
It's recommended to use callbacks when working with dScribe AI's APIs. Below, we'll run through how to quickly setup and test callbacks from dScribe AI locally.
Download and install ngrok
First, download and install ngrok. ngrok allows you to easily work with callbacks by assigning you a perosnal, public URL that will forward incoming requests to your local machine.
To start forwarding requests, simply run ngrok http 8080
(swap 8080 with whatever port your local service is running on). After running ngrok, you should see your public forwarding URL:
Run a local server
Typically, you'd route your requests to the local instance of the app your building. In this example, we'll assume you don't have anything built yet and provide a small Python server that returns 200 to all incoming requests so that we can use ngrok's web interface to view the callback data.
First, ensure Python is installed and use pip to install the FastAPI package. Then, you can copy the following script and save it as server.py
from fastapi import FastAPI, Request
import json
app = FastAPI()
@app.post("/transcribe-callback")
async def transcribe_callback(request: Request):
body = await request.json()
print(json.dumps(body, indent=4))
return {"message": "OK"}
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=8080)
Now, just run the script with python ./server.py
and you should be able to accept requests on your local machine!
Set up the dScribe AI callback
To start using callbacks with dScribe AI's python package, all you need to do is pass the callback URL to the transcribe method we called earlier:
from dscribeai import DScribeAIClient
dscribeai = DScribeAIClient(api_key="<your_api_key>")
transcription_response = dscribeai.transcribe("https://www.tiktok.com/@microsoft/video/7489580646449417515", " https://a656-65-26-17-185.ngrok-free.app/transcribe-callback")
print(transcription_response)
After you run this script, you should see the transcription callback route through ngrok to your local server where it will be printed to the console:
Conclusion
In today's content-rich digital landscape, accessing and analyzing the valuable information within TikTok videos gives developers and businesses a competitive edge. dScribe AI's transcription capabilities provide a simple yet powerful solution for extracting spoken content from TikTok videos using just a URL.
By leveraging dScribe AI, you can transform video content into actionable data, opening up new possibilities for content analysis, research, and accessibility.