Utilisez video-to-text-python pour envoyer un média, créer des tâches de transcription et consulter les résultats.
Le client Python encapsule les API publiques d’upload et de tâches avec des clients synchrone et asynchrone.
Installation
Section intitulée « Installation »pip install video-to-text-pythonInitialisation
Section intitulée « Initialisation »import os
from video_to_text import VideoToTextClient
client = VideoToTextClient( api_key=os.environ["VTT_API_KEY"],)Transcrire un fichier
Section intitulée « Transcrire un fichier »from pathlib import Path
task = client.transcriptions.transcribe_file( Path("meeting.mp4"), language="Auto", timestamp_mode="CHUNK", transcription_mode="balanced", timeout=600,)
print(task.full_text)Utilisez precision lorsque la précision est plus importante que le coût en crédits.
Upload et création manuels
Section intitulée « Upload et création manuels »upload = client.uploads.create({ "filename": "meeting.mp4", "mimetype": "video/mp4",})
content = Path("meeting.mp4").read_bytes()client.uploads.put(upload.upload_url, content, mimetype="video/mp4")
asset = client.uploads.complete(upload.upload_id, { "fileKey": upload.file_key, "fileUrl": upload.file_url, "filename": "meeting.mp4", "mimetype": "video/mp4", "fileSize": len(content),})
created = client.tasks.create({ "assetId": asset.asset_id, "language": "Auto", "timestampMode": "CHUNK", "transcriptionMode": "balanced",})
result = client.tasks.wait(created.transcript_id)print(result.full_text)Client asynchrone
Section intitulée « Client asynchrone »from video_to_text import AsyncVideoToTextClient
async with AsyncVideoToTextClient( api_key=os.environ["VTT_API_KEY"],) as client: task = await client.transcriptions.transcribe_file( Path("meeting.mp4"), transcription_mode="balanced", ) print(task.full_text)Résultats de tâche
Section intitulée « Résultats de tâche »tasks.wait() retourne lorsque la tâche atteint SUCCEEDED. Si la tâche atteint FAILED ou CANCELED, le client lance APIError et utilise show_error comme détail lorsque disponible.
Les détails de tâche incluent full_text, chunks, words, source_duration_ms, result_language, transcription_mode et billed_credits.
from video_to_text import APIError, RateLimitError, UploadError
try: task = client.transcriptions.transcribe_file( Path("meeting.mp4"), transcription_mode="balanced", )except RateLimitError: print("Please retry later.")except UploadError: print("The media upload did not complete.")except APIError as error: print(error.error_code, error.problem.detail)Ressources
Section intitulée « Ressources »Pour le code source, les issues et les contributions, consultez le dépôt GitHub video-to-text-python. Installez la dernière version du package video-to-text-python depuis PyPI.