def test_caption_length(self): captions = SRTReader().read(SAMPLE_SRT.decode(u'utf-8')) self.assertEquals(8, len(captions.get_captions(u"en-US")))
def test_caption_length(self): captions = SRTReader().read(SAMPLE_SRT) self.assertEquals(7, len(captions.get_captions(u"en-US")))
def test_numeric_captions(self): captions = SRTReader().read(SAMPLE_SRT_NUMERIC) self.assertEquals(7, len(captions.get_captions(u"en-US")))
def test_extra_trailing_empty_line(self): captions = SRTReader().read(SAMPLE_SRT_TRAILING_BLANKS) self.assertEquals(2, len(captions.get_captions(u"en-US")))
def test_proper_timestamps(self): captions = SRTReader().read(SAMPLE_SRT) paragraph = captions.get_captions(u"en-US")[2] self.assertEquals(17000000, paragraph.start) self.assertEquals(18752000, paragraph.end)
def test_extra_empty_line(self): captions = SRTReader().read(SAMPLE_SRT_BLANK_LINES) self.assertEquals(2, len(captions.get_captions("en-US")))
import os import sys import codecs import struct import wave from pycaption import SRTReader framerate = 24000 content = codecs.open('output.srt', 'r', 'utf-8').read() srt = SRTReader().read(content, lang='en') caps = srt.get_captions('en') out = wave.open('output.wav', 'w') out.setnchannels(1) out.setsampwidth(2) out.setframerate(framerate) outnframes = 0 for i, cap in enumerate(caps): start = cap.start / 1000000.0 end = cap.end / 1000000.0 nframesToFill = int((end - start) * framerate) wav = wave.open(os.path.join('data_aljazeera', '%d.wav' % (i + 1)), 'r') nframes = wav.getnframes() out.writeframes(wav.readframes(nframes)) wav.close() # need to fill nframesToFill - nframes zero frames for j in xrange(nframesToFill - nframes): out.writeframes(struct.pack('h', 0)) outnframes += nframesToFill
def test_extra_trailing_empty_line(self, sample_srt_trailing_blanks): captions = SRTReader().read(sample_srt_trailing_blanks) assert 2 == len(captions.get_captions("en-US"))
def test_numeric_captions(self, sample_srt_numeric): captions = SRTReader().read(sample_srt_numeric) assert 7 == len(captions.get_captions("en-US"))
def test_proper_timestamps(self, sample_srt): captions = SRTReader().read(sample_srt) paragraph = captions.get_captions("en-US")[2] assert 17000000 == paragraph.start assert 18752000 == paragraph.end
def test_caption_length(self, sample_srt): captions = SRTReader().read(sample_srt) assert 7 == len(captions.get_captions("en-US"))
def test_extra_trailing_empty_line(self): captions = SRTReader().read(SAMPLE_SRT_TRAILING_BLANKS) self.assertEqual(2, len(captions.get_captions(u"en-US")))
parser.add_argument( "--skip-first", action="store_true", default=False, help="If it is True, the first caption will be skipped.") parser.add_argument( "--break-after", type=float, default=0, help="Enable test mode to finish after the given seconds.") parser.add_argument("--output-params", type=str) args = parser.parse_args() srt_text = open(args.srt).read() srt = SRTReader().read(srt_text, lang="en") captions = srt.get_captions("en") reader = imageio.get_reader(args.video) meta_data = reader.get_meta_data() pprint.pprint(meta_data) fps = meta_data["fps"] if args.output_params: output_params = shlex.split(args.output_params) else: output_params = [] print("save to:", args.out) writer = imageio.get_writer( args.out, codec=meta_data["codec"],