made STT_SERVICES dynamic based on vendors.__init__, updated calling code accordingly
This commit is contained in:
@@ -3,14 +3,6 @@ from pathlib import Path
|
|||||||
import sqlite3
|
import sqlite3
|
||||||
|
|
||||||
|
|
||||||
STT_SERVICES = {
|
|
||||||
'amazon': {
|
|
||||||
'cost_per_minute': .024,
|
|
||||||
'free': '60_minutes_per_month_for_the_first_12_months',
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
AWS_BUCKET_NAME_FMTR_MEDIA = 'tatt-media-{}'
|
AWS_BUCKET_NAME_FMTR_MEDIA = 'tatt-media-{}'
|
||||||
AWS_BUCKET_NAME_FMTR_TRANSCRIPT = 'tatt-transcript-{}'
|
AWS_BUCKET_NAME_FMTR_TRANSCRIPT = 'tatt-transcript-{}'
|
||||||
|
|
||||||
|
|||||||
@@ -1,27 +1,33 @@
|
|||||||
from tatt import config
|
from tatt import config
|
||||||
from tatt import vendors
|
from tatt import vendors
|
||||||
|
|
||||||
|
LB = '\n'
|
||||||
|
TAB = '\t'
|
||||||
|
|
||||||
|
|
||||||
def make_string_all_services(free_only=False):
|
def make_string_all_services(free_only=False):
|
||||||
all_services_string = (
|
all_services_string_formatter = (
|
||||||
'\nHere are all the available '
|
"Here are all the available {}speech-to-text-services:\n\n"
|
||||||
f'{"free " if free_only else ""}speech-to-text services:'
|
)
|
||||||
'\n\n'
|
|
||||||
'\n'.join(['{}{}{}{}'.format('\t', service_name, '\t\t',
|
|
||||||
|
|
||||||
f'({info["free"].replace("_", " ")})'
|
if free_only:
|
||||||
if isinstance(info["free"], str) else ""
|
all_services_string = all_services_string_formatter.format("free ")
|
||||||
|
else:
|
||||||
)
|
all_services_string = all_services_string_formatter.format("")
|
||||||
|
|
||||||
|
for service_name, module in vendors.STT_SERVICES.items():
|
||||||
|
if free_only and module.cost_per_15_seconds > 0:
|
||||||
|
continue
|
||||||
|
all_services_string += (
|
||||||
|
f'{TAB}{service_name}{TAB}{TAB}${module.cost_per_15_seconds} per 15 seconds'
|
||||||
|
)
|
||||||
|
|
||||||
for service_name, info in
|
|
||||||
config.STT_SERVICES.items()]) + '\n'
|
|
||||||
)
|
|
||||||
return all_services_string
|
return all_services_string
|
||||||
|
|
||||||
|
|
||||||
def get_service(service_name):
|
def get_service(service_name):
|
||||||
return getattr(getattr(vendors, service_name), config.SERVICE_CLASS_NAME)
|
module = vendors.STT_SERVICES[service_name]
|
||||||
|
return getattr(module, config.SERVICE_CLASS_NAME)
|
||||||
|
|
||||||
|
|
||||||
def print_transcription_jobs(jobs):
|
def print_transcription_jobs(jobs):
|
||||||
@@ -49,7 +55,7 @@ def print_transcription_jobs(jobs):
|
|||||||
|
|
||||||
def get_transcription_jobs(service_name=None, name=None, status=None):
|
def get_transcription_jobs(service_name=None, name=None, status=None):
|
||||||
all_jobs = {}
|
all_jobs = {}
|
||||||
for stt_name, data in config.STT_SERVICES.items():
|
for stt_name in vendors.STT_SERVICES:
|
||||||
if service_name is None or service_name == stt_name:
|
if service_name is None or service_name == stt_name:
|
||||||
service = get_service(stt_name)
|
service = get_service(stt_name)
|
||||||
service._setup() # check for AWS credentials and create buckets
|
service._setup() # check for AWS credentials and create buckets
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ def get(name, file):
|
|||||||
@click.option('--status', type=str, help="completed | failed | in_progress")
|
@click.option('--status', type=str, help="completed | failed | in_progress")
|
||||||
def list(name, service, status):
|
def list(name, service, status):
|
||||||
"""Lists available STT services."""
|
"""Lists available STT services."""
|
||||||
if service is not None and service not in config.STT_SERVICES:
|
if service is not None and service not in vendors.STT_SERVICES:
|
||||||
raise click.ClickException(f'no such service: {service}')
|
raise click.ClickException(f'no such service: {service}')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -67,7 +67,7 @@ def services(free_only):
|
|||||||
@click.argument('service_name', type=str)
|
@click.argument('service_name', type=str)
|
||||||
def this(dry_run, media_filepath, service_name):
|
def this(dry_run, media_filepath, service_name):
|
||||||
"""Sends a media file to be transcribed."""
|
"""Sends a media file to be transcribed."""
|
||||||
if service_name not in config.STT_SERVICES:
|
if service_name not in vendors.STT_SERVICES:
|
||||||
print()
|
print()
|
||||||
raise click.ClickException(
|
raise click.ClickException(
|
||||||
f'No such service! {print_all_services(print_=False)}')
|
f'No such service! {print_all_services(print_=False)}')
|
||||||
|
|||||||
4
tatt/vendors/__init__.py
vendored
4
tatt/vendors/__init__.py
vendored
@@ -1 +1,5 @@
|
|||||||
from tatt.vendors import amazon
|
from tatt.vendors import amazon
|
||||||
|
|
||||||
|
STT_VENDORS = {
|
||||||
|
'amazon': amazon,
|
||||||
|
}
|
||||||
|
|||||||
4
tatt/vendors/amazon.py
vendored
4
tatt/vendors/amazon.py
vendored
@@ -12,6 +12,7 @@ from tatt import exceptions
|
|||||||
NAME = 'amazon'
|
NAME = 'amazon'
|
||||||
BUCKET_NAME_MEDIA = config.AWS_BUCKET_NAME_FMTR_MEDIA.format(NAME)
|
BUCKET_NAME_MEDIA = config.AWS_BUCKET_NAME_FMTR_MEDIA.format(NAME)
|
||||||
BUCKET_NAME_TRANSCRIPT = config.AWS_BUCKET_NAME_FMTR_TRANSCRIPT.format(NAME)
|
BUCKET_NAME_TRANSCRIPT = config.AWS_BUCKET_NAME_FMTR_TRANSCRIPT.format(NAME)
|
||||||
|
cost_per_15_seconds = .024 / 4
|
||||||
|
|
||||||
|
|
||||||
def check_for_config():
|
def check_for_config():
|
||||||
@@ -30,7 +31,6 @@ class Transcriber:
|
|||||||
|
|
||||||
bucket_names = {'media': BUCKET_NAME_MEDIA,
|
bucket_names = {'media': BUCKET_NAME_MEDIA,
|
||||||
'transcript': BUCKET_NAME_TRANSCRIPT}
|
'transcript': BUCKET_NAME_TRANSCRIPT}
|
||||||
service_name = 'amazon'
|
|
||||||
|
|
||||||
def __init__(self, filepath):
|
def __init__(self, filepath):
|
||||||
self._setup()
|
self._setup()
|
||||||
@@ -62,7 +62,7 @@ class Transcriber:
|
|||||||
return self._request_transcription()
|
return self._request_transcription()
|
||||||
except tr.exceptions.ConflictException:
|
except tr.exceptions.ConflictException:
|
||||||
raise exceptions.AlreadyExistsError(
|
raise exceptions.AlreadyExistsError(
|
||||||
f'{self.basename} already exists on {self.service_name}')
|
f'{self.basename} already exists on {NAME}')
|
||||||
|
|
||||||
def _upload_file(self):
|
def _upload_file(self):
|
||||||
s3.Bucket(self.bucket_names['media']).upload_file(
|
s3.Bucket(self.bucket_names['media']).upload_file(
|
||||||
|
|||||||
Reference in New Issue
Block a user