Skip to main content

Introduction

This package is a set of tools to transform captions from one format to another. You will find Writer and Reader for each format and a script if you want to use it in command line.

Supported Format:

  • sbv Reader and Writer

  • srt Reader and Writer

  • ttml Reader and Writer

  • transcript Reader and Writer

How to use (API)

You can read the provided unittest to have complete examples:

from captionstransformer.sbv import Reader
from captionstransformer.ttml import Writer
from StringIO import StringIO
test_content = StringIO(u"""
0:00:03.490,0:00:07.430
>> FISHER: All right. So, let's begin.
This session is: Going Social

0:00:07.430,0:00:11.600
with the YouTube APIs. I am
Jeff Fisher,

0:00:11.600,0:00:14.009
and this is Johann Hartmann,
we're presenting today.

0:00:14.009,0:00:15.889
[pause]
""")
reader = Reader(test_content)

captions = reader.read()
len(captions) == 4
first = captions[0]
type(first.text) == unicode
first.text == u">> FISHER: All right. So, let's begin.\nThis session is: Going Social\n"

# next get a writer
filelike = StringIO()
writer = Writer(filelike)
writer.set_captions(captions)
text = writer.captions_to_text()
text.startswith(u"""<tt xml:lang="" xmlns="http://www.w3.org/ns/ttml"><body><div>""")
writer.write()
writer.close()

About Formats

This quite hard to find simple documentation about existing caption format. Here is a set of existing named caption format:

SubViewer (SUB):

00:04:35.03,00:04:38.82
Hello guys... please sit down...

00:05:00.19,00:05:03.47
M. Franklin,[br]are you crazy?

Youtube (SBV):

0:00:03.490,0:00:07.430
FISHER: All right. So, let's begin.
This session is: Going Social

0:00:07.430,0:00:11.600
with the YouTube APIs. I am
Jeff Fisher,

0:00:11.600,0:00:14.009
and this is Johann Hartmann,
we're presenting today.

0:00:14.009,0:00:15.889
[pause]

SubRip (SRT):

1
00:00:03,490 --> 00:00:07,430
FISHER: All right. So, let's begin.
This session is: Going Social

00:00:07,430 --> 00:00:11,600
with the YouTube APIs. I am
Jeff Fisher,

2
00:00:11,600 --> 00:00:14,009
and this is Johann Hartmann,
we're presenting today.

3
00:00:14,009 --> 00:00:15,889
[pause]

Timed Text Markup Language (TTML):

<tt xml:lang="" xmlns="http://www.w3.org/ns/ttml">
  <body region="subtitleArea">
    <div>
      <p xml:id="subtitle1" begin="0.76s" end="3.45s">
        It seems a paradox, does it not,
      </p>
      <p xml:id="subtitle2" begin="5.0s" end="10.0s">
        that the image formed on<br/>
        the Retina should be inverted?
      </p>
    </div>
  </body>
</tt>

Transcript

<?xml version="1.0" encoding="utf-8" ?>
<transcript>
    <text start="10" dur="2">Hi, I&amp;#39;m Emily from Nomensa</text>
    <text start="12" dur="3">and today I&amp;#39;m going to be talking about the order of content on your pages.</text>
    <text start="16" dur="6">Making sure the content on your web pages is presented logically is a really important part of web accessibility.</text>
    <text start="23" dur="2">Page content should be ordered so it makes sense</text>
</transcript>

Microsoft SAMI (SAMI, SMI):

<SAMI>
<Head>
   <Title>President John F. Kennedy Speech</Title>
   <SAMIParam>
      Copyright {(C)Copyright 1997, Microsoft Corporation}
      Media {JF Kennedy.wav}
      Metrics {time:ms; duration: 73000;}
      Spec {MSFT:1.0;}
   </SAMIParam>
</Head>

<Body>
   <SYNC Start=0>
      <P Class=ENUSCC ID=Source>Pres. John F. Kennedy
   <SYNC Start=10>
      <P Class=ENUSCC>Let the word go forth,
         from this time and place to friend and foe
         alike that the torch
</Body>
</SAMI>

Credits

Companies

cirb CIRB / CIBG

makinacom

Authors

Changelog

1.2.1 (2012-08-07)

  • force rawcontent to be unicode

1.2 (2012-08-06)

  • add support for time format like start=”1.8” in transcript

  • add youtube download captions: captionstransformer.youtube.get_captions & get_reader

1.1 (2012-08-05)

  • add extension and mimetype info into REGISTRY

  • add id info into REGISTRY

1.0 (2012-07-23)

  • Initial release

Metadata

Release files for captionstransformer 1.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for captionstransformer 1.2.1
File Size Uploaded Provenance Actions
captionstransformer-1.2.1.zip 41.5 kB Without provenance Details for captionstransformer-1.2.1.zip

Release files / captionstransformer-1.2.1.zip

Download URL captionstransformer-1.2.1.zip
Size 41.5 kB
Tags Source
SHA-256 checksum
How to use checksums
6f5e0eb7ba49f0286dd183cbc082c5f2bffe790996ef3e749dbac5d28f8d86d8
BLAKE2b-256 checksum
How to use checksums
3c5429c698d1690d7f35f387bba36bc135d5cf2dfce1c472b5d491e4529b3147
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for captionstransformer 1.2.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page