Best Python code snippet using localstack_python
aws_transcribe_info.py
Source:aws_transcribe_info.py
...129 Status=module.params['status'],130 JobNameContains=module.params['name_contains'],131 ), True132 else:133 return client.list_transcription_jobs(134 Status=module.params['status'],135 JobNameContains=module.params['name_contains'],136 ), False137 elif module.params['list_vocabulary_filters']:138 if client.can_paginate('list_vocabulary_filters'):139 paginator = client.get_paginator('list_vocabulary_filters')140 return paginator.paginate(), True141 else:142 return client.list_vocabulary_filters(), False143 else:144 return None, False145 except (BotoCoreError, ClientError) as e:146 module.fail_json_aws(e, msg='Failed to fetch Amazon Transcribe Service details')147def main():...
aws_transcriber.py
Source:aws_transcriber.py
...42 )43 print(f"Response: {response}")44 # return a list of transcription job names45 return [obj["Key"] for obj in response["Contents"] if pattern in obj["Key"]]46def list_transcription_jobs():47 """List all transcription jobs"""48 transcribe = boto3.client("transcribe")49 response = transcribe.list_transcription_jobs()50 return response["TranscriptionJobSummaries"]51# get the uri of the transcription job to download the transcription52def get_transcription_uri(job_name):53 """Get the uri of a transcription job"""54 transcribe = boto3.client("transcribe")55 response = transcribe.get_transcription_job(TranscriptionJobName=job_name)56 uri_json = response["TranscriptionJob"]["Transcript"]["TranscriptFileUri"]57 return uri_json58# download the transcription using requests59def download_transcription(uri_json, filename):60 """Download a transcription"""61 response = requests.get(uri_json, timeout=30)62 with open(filename, "w", encoding="utf-8") as f:63 f.write(response.text)64# read the transcription from from a file and return only the text65def read_transcription(filename):66 """Read a transcription"""67 with open(filename, "r", encoding="utf-8") as f:68 data = json.load(f)69 return data["results"]["transcripts"][0]["transcript"]70# write a function that takes a transcription job name, downloads the transcription, and returns the text71def get_transcription_text(job_name):72 """Get the text of a transcription"""73 uri_json = get_transcription_uri(job_name)74 # print(f"Downloading transcription from {uri_json}")75 filename = f"{job_name}.json"76 print(f"Saving transcription to {filename}")77 download_transcription(uri_json, filename)78 print(f"Transcription downloaded to {filename}")79 text = read_transcription(filename)80 # delete the file81 pathlib.Path(filename).unlink()82 return text83@click.group()84def cli():85 pass86@cli.command("transcribe")87@click.argument("bucket_name")88def transcribe_all(bucket_name):89 """Transcribe all files in a bucket90 Example: python aws_transcriber.py transcribe my-bucket91 """92 result = transcribe_all_files(bucket_name)93 print(f"Transcribed {len(result)} files")94@cli.command("list-jobs")95def list_jobs():96 """List all transcription jobs97 Example: python aws_transcriber.py list98 """99 result = list_transcription_jobs()100 print(f"Found {len(result)} jobs")101 for job in result:102 print(job["TranscriptionJobName"])103@cli.command("get-results")104@click.argument("job_name")105def get_results(job_name):106 """Get the results of a transcription job107 Example: python aws_transcriber.py get-results my-job108 """109 result = get_transcription_text(job_name)110 print(result)111@cli.command("summarize")112@click.argument("job_name")113def summarize(job_name):...
test_aws.py
Source:test_aws.py
...37import os38transcribe = boto3.client('transcribe')39job_uri_base = "s3://thesis-asr-testing-bucket/"40jobs = []41jobList = transcribe.list_transcription_jobs(MaxResults=100)42nextToken = jobList['NextToken']43jobs.append(jobList["TranscriptionJobSummaries"])44while len(nextToken) > 0 and nextToken != None:45 print(len(jobs))46 jobList = transcribe.list_transcription_jobs(NextToken=nextToken, MaxResults=100)47 jobs.append(jobList["TranscriptionJobSummaries"])48 try:49 nextToken = jobList['NextToken']50 except:51 break52# In[3]:53import requests54import json55from csv import writer56# Reads the transcriptions and saves them to a file for further processing57timit_labels = {}58with open('./timit.json', 'r') as t:59 timit_labels = json.load(t)60 ...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!