Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,9 @@ dist/
.DS_Store
MANIFEST
*#*
.vscode
.vscode
/.vs/autosub/v15/.suo
/.vs
/autosub.sln
/autosub.pyproj
/.idea
21 changes: 16 additions & 5 deletions autosub/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -99,15 +99,15 @@ 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

except KeyboardInterrupt:
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.
"""
Expand Down Expand Up @@ -163,6 +163,17 @@ def is_exe(file_path):
return None


def ffmpeg_check():
"""
Return the ffmpeg executable name. "null" returned when no executable exists.
"""
if which("ffmpeg"):
return "ffmpeg"
if which("ffmpeg.exe"):
return "ffmpeg.exe"
return None


def extract_audio(filename, channels=1, rate=16000):
"""
Extract audio from an input file to a temporary WAV file.
Expand All @@ -171,10 +182,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
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down