From 0bc5fbcbae8452427fa1a93f8b086cfd722e4d07 Mon Sep 17 00:00:00 2001 From: mountwebs <35745999+mountwebs@users.noreply.github.com> Date: Mon, 17 Jun 2019 20:37:28 +0200 Subject: [PATCH 1/9] Added argument for min and max region size. --- autosub/__init__.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/autosub/__init__.py b/autosub/__init__.py index d85e4db9..d5d593a7 100644 --- a/autosub/__init__.py +++ b/autosub/__init__.py @@ -238,6 +238,8 @@ def generate_subtitles( # pylint: disable=too-many-locals,too-many-arguments dst_language=DEFAULT_DST_LANGUAGE, subtitle_file_format=DEFAULT_SUBTITLE_FORMAT, api_key=None, + min_region_size=0.5, + max_region_size=6, ): """ Given an input audio/video file, generate subtitles in the specified language and format. @@ -375,6 +377,10 @@ def main(): action='store_true') parser.add_argument('--list-languages', help="List all available source/destination languages", action='store_true') + parser.add_argument('-m', '--min', help="Minimum region size", + default=0.5) + parser.add_argument('-M', '--max', help="Maximum region size", + default=6) args = parser.parse_args() @@ -402,6 +408,8 @@ def main(): api_key=args.api_key, subtitle_file_format=args.format, output=args.output, + min_region_size=int(args.min), + max_region_size=int(args.max), ) print("Subtitles file created at {}".format(subtitle_file_path)) except KeyboardInterrupt: From 1d0afb6653eb597a05c0b740b99dac2869ad403e Mon Sep 17 00:00:00 2001 From: mountwebs <35745999+mountwebs@users.noreply.github.com> Date: Mon, 17 Jun 2019 21:15:38 +0200 Subject: [PATCH 2/9] Update .travis.yml --- .travis.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4d65ed3e..2972d2a3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,3 @@ python: - "2.7" install: - pip install . - - pip install pylint -script: - - pylint autosub From 8e7723bf08572b5d6c8b41349aa9c650f71cf259 Mon Sep 17 00:00:00 2001 From: mountwebs <35745999+mountwebs@users.noreply.github.com> Date: Mon, 17 Jun 2019 21:18:42 +0200 Subject: [PATCH 3/9] Update .travis.yml --- .travis.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2972d2a3..4e4311d0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,3 @@ language: python python: - "2.7" -install: - - pip install . From 93ebb357c01ee45d5f485463795776674714eff5 Mon Sep 17 00:00:00 2001 From: mountwebs <35745999+mountwebs@users.noreply.github.com> Date: Mon, 17 Jun 2019 21:29:23 +0200 Subject: [PATCH 4/9] Changed .travis.yaml back to original --- .travis.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.travis.yml b/.travis.yml index 4e4311d0..4d65ed3e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,8 @@ language: python python: - "2.7" +install: + - pip install . + - pip install pylint +script: + - pylint autosub From a76a4e6944b3dd1d05193a8d53a6c32f7ee0bf8d Mon Sep 17 00:00:00 2001 From: mountwebs <35745999+mountwebs@users.noreply.github.com> Date: Mon, 17 Jun 2019 21:41:51 +0200 Subject: [PATCH 5/9] Update __init__.py --- autosub/__init__.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/autosub/__init__.py b/autosub/__init__.py index d5d593a7..06ded2c5 100644 --- a/autosub/__init__.py +++ b/autosub/__init__.py @@ -35,7 +35,6 @@ DEFAULT_SRC_LANGUAGE = 'en' DEFAULT_DST_LANGUAGE = 'en' - def percentile(arr, percent): """ Calculate the given percentile of arr. @@ -237,16 +236,16 @@ def generate_subtitles( # pylint: disable=too-many-locals,too-many-arguments src_language=DEFAULT_SRC_LANGUAGE, dst_language=DEFAULT_DST_LANGUAGE, subtitle_file_format=DEFAULT_SUBTITLE_FORMAT, - api_key=None, min_region_size=0.5, max_region_size=6, + api_key=None, ): """ Given an input audio/video file, generate subtitles in the specified language and format. """ audio_filename, audio_rate = extract_audio(source_path) - regions = find_speech_regions(audio_filename) + regions = find_speech_regions(audio_filename, min_region_size=min_region_size, max_region_size=max_region_size) pool = multiprocessing.Pool(concurrency) converter = FLACConverter(source_path=audio_filename) @@ -356,6 +355,8 @@ def main(): """ Run autosub as a command-line program. """ + + parser = argparse.ArgumentParser() parser.add_argument('source_path', help="Path to the video or audio file to subtitle", nargs='?') @@ -370,6 +371,10 @@ def main(): default=DEFAULT_SRC_LANGUAGE) parser.add_argument('-D', '--dst-language', help="Desired language for the subtitles", default=DEFAULT_DST_LANGUAGE) + parser.add_argument('-m', '--min', help="Minimum region size", + default=0.5) + parser.add_argument('-M', '--max', help="Maximum region size", + default=6) parser.add_argument('-K', '--api-key', help="The Google Translate API key to be used. \ (Required for subtitle translation)") @@ -377,10 +382,6 @@ def main(): action='store_true') parser.add_argument('--list-languages', help="List all available source/destination languages", action='store_true') - parser.add_argument('-m', '--min', help="Minimum region size", - default=0.5) - parser.add_argument('-M', '--max', help="Maximum region size", - default=6) args = parser.parse_args() @@ -407,9 +408,9 @@ def main(): dst_language=args.dst_language, api_key=args.api_key, subtitle_file_format=args.format, - output=args.output, min_region_size=int(args.min), max_region_size=int(args.max), + output=args.output, ) print("Subtitles file created at {}".format(subtitle_file_path)) except KeyboardInterrupt: From 8ffeddde148f813b09df12d7410ec82842fa2cd1 Mon Sep 17 00:00:00 2001 From: mountwebs <35745999+mountwebs@users.noreply.github.com> Date: Thu, 3 Oct 2019 18:00:49 +0200 Subject: [PATCH 6/9] Update README.md --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b89840c5..ea279521 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,10 @@ # Autosub - + +This is a modified verson of Autosub. I have added arguments for minimum and maximum region size (length of audio to be transcribed in each "subtitle"). + +Personally I found this very convenient when using autosub to transcribe interviews (yes, autosub works great for that application), but it might be useful in other cases too. + + ### Auto-generated subtitles for any video Autosub is a utility for automatic speech recognition and subtitle generation. It takes a video or an audio file as input, performs voice activity detection to find speech regions, makes parallel requests to Google Web Speech API to generate transcriptions for those regions, (optionally) translates them to a different language, and finally saves the resulting subtitles to disk. It supports a variety of input and output languages (to see which, run the utility with the argument `--list-languages`) and can currently produce subtitles in either the [SRT format](https://en.wikipedia.org/wiki/SubRip) or simple [JSON](https://en.wikipedia.org/wiki/JSON). From 7203ab7d653f8ff3e60a746d32a2137e64e4787a Mon Sep 17 00:00:00 2001 From: mountwebs <35745999+mountwebs@users.noreply.github.com> Date: Thu, 3 Oct 2019 18:03:39 +0200 Subject: [PATCH 7/9] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ea279521..67d85f81 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # Autosub -This is a modified verson of Autosub. I have added arguments for minimum and maximum region size (length of audio to be transcribed in each "subtitle"). +*This is a modified verson of Autosub. I have added arguments for minimum and maximum region size (length of audio to be transcribed in each "subtitle").* -Personally I found this very convenient when using autosub to transcribe interviews (yes, autosub works great for that application), but it might be useful in other cases too. +*Personally I found this very convenient when using autosub to transcribe interviews (yes, autosub works great for that application), but it might be useful in other cases too.* ### Auto-generated subtitles for any video From 1776c1b7d7b8a82aabfba786993b03d2cf32b29d Mon Sep 17 00:00:00 2001 From: mountwebs <35745999+mountwebs@users.noreply.github.com> Date: Thu, 3 Oct 2019 18:08:08 +0200 Subject: [PATCH 8/9] Update README.md --- README.md | 55 ++++++------------------------------------------------- 1 file changed, 6 insertions(+), 49 deletions(-) diff --git a/README.md b/README.md index 67d85f81..b7e6e82d 100644 --- a/README.md +++ b/README.md @@ -1,52 +1,9 @@ -# Autosub +# Autosub -*This is a modified verson of Autosub. I have added arguments for minimum and maximum region size (length of audio to be transcribed in each "subtitle").* +This is a modified verson of [Autosub](https://github.com/agermanidis/autosub). I have added arguments for minimum and maximum region size (length of audio to be transcribed in each "subtitle"). -*Personally I found this very convenient when using autosub to transcribe interviews (yes, autosub works great for that application), but it might be useful in other cases too.* +Personally I found this very convenient when using autosub to transcribe interviews (yes, autosub works great for that application), but it might be useful in other cases too. - -### Auto-generated subtitles for any video - -Autosub is a utility for automatic speech recognition and subtitle generation. It takes a video or an audio file as input, performs voice activity detection to find speech regions, makes parallel requests to Google Web Speech API to generate transcriptions for those regions, (optionally) translates them to a different language, and finally saves the resulting subtitles to disk. It supports a variety of input and output languages (to see which, run the utility with the argument `--list-languages`) and can currently produce subtitles in either the [SRT format](https://en.wikipedia.org/wiki/SubRip) or simple [JSON](https://en.wikipedia.org/wiki/JSON). - -### Installation - -1. Install [ffmpeg](https://www.ffmpeg.org/). -2. Run `pip install autosub`. - -### Usage - -``` -$ autosub -h -usage: autosub [-h] [-C CONCURRENCY] [-o OUTPUT] [-F FORMAT] [-S SRC_LANGUAGE] - [-D DST_LANGUAGE] [-K API_KEY] [--list-formats] - [--list-languages] - [source_path] - -positional arguments: - source_path Path to the video or audio file to subtitle - -optional arguments: - -h, --help show this help message and exit - -C CONCURRENCY, --concurrency CONCURRENCY - Number of concurrent API requests to make - -o OUTPUT, --output OUTPUT - Output path for subtitles (by default, subtitles are - saved in the same directory and name as the source - path) - -F FORMAT, --format FORMAT - Destination subtitle format - -S SRC_LANGUAGE, --src-language SRC_LANGUAGE - Language spoken in source file - -D DST_LANGUAGE, --dst-language DST_LANGUAGE - Desired language for the subtitles - -K API_KEY, --api-key API_KEY - The Google Translate API key to be used. (Required for - subtitle translation) - --list-formats List all available subtitle formats - --list-languages List all available source/destination languages -``` - -### License - -MIT +Added arguments: + -m MIN, --min MIN Minimum region size + -M MAX, --max MAX Maximum region size From 936ce67de214921b64181d54e7b710169a758652 Mon Sep 17 00:00:00 2001 From: mountwebs <35745999+mountwebs@users.noreply.github.com> Date: Thu, 3 Oct 2019 18:08:54 +0200 Subject: [PATCH 9/9] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b7e6e82d..a989b2d6 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Autosub -This is a modified verson of [Autosub](https://github.com/agermanidis/autosub). I have added arguments for minimum and maximum region size (length of audio to be transcribed in each "subtitle"). +This is a modified verson of [Autosub](https://github.com/agermanidis/autosub) with added arguments for minimum and maximum region size (length of audio to be transcribed in each "subtitle"). Personally I found this very convenient when using autosub to transcribe interviews (yes, autosub works great for that application), but it might be useful in other cases too.