From bd60c2ba7ebbf4a2f74ed8840712521fe4b28165 Mon Sep 17 00:00:00 2001 From: Wang Jiaxiang Date: Thu, 10 Jan 2019 13:17:33 +0800 Subject: [PATCH 1/4] Fix "ffmpeg.exe" causes "Dependency not found: ffmpeg" on Windows --- .gitignore | 6 +++++- autosub/__init__.py | 16 ++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 10e73277d..3819ae371 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,8 @@ dist/ .DS_Store MANIFEST *#* -.vscode \ No newline at end of file +.vscode +/.vs/autosub/v15/.suo +/.vs +/autosub.sln +/autosub.pyproj diff --git a/autosub/__init__.py b/autosub/__init__.py index 61019464b..d5cd7e91a 100644 --- a/autosub/__init__.py +++ b/autosub/__init__.py @@ -163,6 +163,18 @@ def is_exe(file_path): return None +def ffmpeg_check(): + """ + Return the ffmpeg executable name. "null" returned when no executable exsits. + """ + if which("ffmpeg"): + return "ffmpeg" + elif which("ffmpeg.exe"): + return "ffmpeg.exe" + else: + return None + + def extract_audio(filename, channels=1, rate=16000): """ Extract audio from an input file to a temporary WAV file. @@ -171,10 +183,10 @@ def extract_audio(filename, channels=1, rate=16000): if not os.path.isfile(filename): print("The given file does not exist: {}".format(filename)) raise Exception("Invalid filepath: {}".format(filename)) - if not which("ffmpeg"): + if not ffmpeg_check(): print("ffmpeg: Executable not found on machine.") raise Exception("Dependency not found: ffmpeg") - command = ["ffmpeg", "-y", "-i", filename, + command = [ffmpeg_check(), "-y", "-i", filename, "-ac", str(channels), "-ar", str(rate), "-loglevel", "error", temp.name] use_shell = True if os.name == "nt" else False From 6a1f712b66f6d817d7c99ee43b9c00a92df7692c Mon Sep 17 00:00:00 2001 From: Wang Jiaxiang Date: Thu, 10 Jan 2019 14:33:18 +0800 Subject: [PATCH 2/4] Fix "ValueError" when the response data of "SpeechRecgnizer" coundn't be parsed to JSON Object. --- autosub/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autosub/__init__.py b/autosub/__init__.py index d5cd7e91a..8e9db7527 100644 --- a/autosub/__init__.py +++ b/autosub/__init__.py @@ -99,7 +99,7 @@ def __call__(self, data): line = json.loads(line) line = line['result'][0]['alternative'][0]['transcript'] return line[:1].upper() + line[1:] - except IndexError: + except (ValueError, IndexError): # no result continue From 0f2ef118f8e3515a2ca4d44231d8c100a2d55e59 Mon Sep 17 00:00:00 2001 From: BingLingFanSub Date: Sun, 10 Feb 2019 17:38:40 +0800 Subject: [PATCH 3/4] Fix pylint issues and windows temp file issues --- .gitignore | 1 + autosub/__init__.py | 13 ++++++------- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 3819ae371..491cdf911 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ MANIFEST /.vs /autosub.sln /autosub.pyproj +/.idea diff --git a/autosub/__init__.py b/autosub/__init__.py index 8e9db7527..0cc7777c0 100644 --- a/autosub/__init__.py +++ b/autosub/__init__.py @@ -61,7 +61,7 @@ def __call__(self, region): start, end = region start = max(0, start - self.include_before) end += self.include_after - temp = tempfile.NamedTemporaryFile(suffix='.flac') + temp = tempfile.NamedTemporaryFile(suffix='.flac', delete=False) command = ["ffmpeg", "-ss", str(start), "-t", str(end - start), "-y", "-i", self.source_path, "-loglevel", "error", temp.name] @@ -99,7 +99,7 @@ def __call__(self, data): line = json.loads(line) line = line['result'][0]['alternative'][0]['transcript'] return line[:1].upper() + line[1:] - except (ValueError, IndexError): + except (ValueError, IndexError): # no result continue @@ -107,7 +107,7 @@ def __call__(self, data): return None -class Translator(object): # pylint: disable=too-few-public-methods +class Translator(object): # pylint: disable=too-few-public-methods """ Class for translating a sentence from a one language to another. """ @@ -165,14 +165,13 @@ def is_exe(file_path): def ffmpeg_check(): """ - Return the ffmpeg executable name. "null" returned when no executable exsits. + Return the ffmpeg executable name. "null" returned when no executable exists. """ if which("ffmpeg"): return "ffmpeg" - elif which("ffmpeg.exe"): + if which("ffmpeg.exe"): return "ffmpeg.exe" - else: - return None + return None def extract_audio(filename, channels=1, rate=16000): From e4296672564364dbccf389eb1c3b79e3e7670035 Mon Sep 17 00:00:00 2001 From: BingLingFanSub Date: Sun, 10 Feb 2019 20:30:23 +0800 Subject: [PATCH 4/4] =?UTF-8?q?Fix=20setup.py=20distutils=E2=80=99=20build?= =?UTF-8?q?=5Fpy=20fails=20package=20string=20is=20unicode?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index c9ac20c0a..f1b35f179 100644 --- a/setup.py +++ b/setup.py @@ -26,7 +26,7 @@ author='Anastasis Germanidis', author_email='agermanidis@gmail.com', url='https://github.com/agermanidis/autosub', - packages=['autosub'], + packages=[str('autosub')], entry_points={ 'console_scripts': [ 'autosub = autosub:main',