Best Python code snippet using localstack_python
transcribe.py
Source: transcribe.py
...25 input_file_content = get_file_contents(input_file)26 file_name = input_file.filename27 #print("This is your file name: " + file_name)28 try:29 transcript_text = get_transcription_job(file_name)30 except Exception as e:31 #print("Generating new transcript")32 s3_upload(file_name, input_file)33 #print("Uploaded file to S3")34 transcript_text = transcribe_audio(file_name, file_name)35 response = jsonify({"transcript": transcript_text})36 response.headers.add('Access-Control-Allow-Origin', '*')37 #print("Transcribed text: " + transcript_text)38 return response39def s3_upload(file_name, input_file):40 """41 Connects with s3 and creates a file under the given bucket name.42 :param file_name: name of the file the user uploaded, and is the name of the file in the s3 bucket.43 :param input_file: the file content44 :return: none45 """46 #print("Starting s3_upload")47 #print("This is your file name: " + file_name)48 try:49 s3_client = boto3.client('s3')50 response = s3_client.upload_file(FILE_PATH + file_name, S3_BUCKET_NAME, file_name, ExtraArgs={"ContentType": input_file.content_type})51 #print("Completed s3_upload")52 except botocore.exceptions.ClientError as error:53 #print("s3_upload error: " + str(error))54 raise error55def transcribe_audio(project_name, file_name):56 """57 This will start a transcription job in AWS to transcribe the user's given audio file.58 :param project_name: name under which the transcription job runs59 :param file_name: name of the file in the given s3 bucket60 :return: the transcribed text61 """62 #print("transcribe_audio project name: " + project_name)63 transcribe_client = get_transcribe_client()64 file_url = "s3://" + S3_BUCKET_NAME + "/" + file_name65 #print("File Url:" + file_url)66 transcribe_client.start_transcription_job(67 TranscriptionJobName = project_name,68 Media = {"MediaFileUri" : file_url},69 MediaFormat = 'mp3',70 LanguageCode = 'en-US'71 )72 count = 10073 74 while count > 0:75 transcript_text = get_transcription_job(project_name)76 if transcript_text is not None:77 #print(transcript_text)78 return transcript_text79 print("Transcribe in Progress")80 count -= 181 time.sleep(10)82 #print("Took too long to transcribe")83 return "Took too long to transcribe"84def get_transcription_job(project_name):85 """86 This gets the transcription job back from AWS, and reads the status the job returned.87 If it is completed, a url will be present in the returned data.88 This url points to the transcribed text, which is stored in a common s3 bucket, and it will contain the transcribed text.89 By reading the url content, you can get the transcribed text from a dictionary.90 If it fails, it will return request failed.91 :param project_name:92 :return:93 """94 try:95 transcribe_client = get_transcribe_client()96 #print("This is your project name: " + project_name)97 project = transcribe_client.get_transcription_job(TranscriptionJobName = project_name)98 project_status = project["TranscriptionJob"]["TranscriptionJobStatus"]99 #print(f"Waiting for {project_name}. Current status is {project_status}.")100 if project_status in ["COMPLETED", "FAILED"]:101 #print(f"Project {project_name} is {project_status}.")102 if project_status == 'COMPLETED':103 #print(104 #f"Download the transcript from\n"105 #f"\t{project['TranscriptionJob']['Transcript']['TranscriptFileUri']}."106 #f"\t{project}."107 #)108 ssl._create_default_https_context = ssl._create_unverified_context109 url = project['TranscriptionJob']['Transcript']['TranscriptFileUri']110 #print(url)111 response = urllib.request.urlopen(url)...
aws.py
Source: aws.py
...20 },21 OutputBucketName=output_bucket_name22 )23 return response24def get_transcription_job(transcription_job_name):25 client = boto3.client('transcribe')26 response = client.get_transcription_job(27 TranscriptionJobName=transcription_job_name28 )29 return response30if __name__ == "__main__":31 bucket_name = 'transcribe.nstech'32 file_name = 'news.mp3'33 object_name = datetime.now().strftime('%Y%m%d-%H%M%S-') + file_name34 upload_object(bucket_name, file_name, object_name)35 job_name = object_name.replace('.', '_')36 start_job(job_name, 'ja-JP', 's3://' + bucket_name + '/' + object_name, bucket_name)37 while True:38 response = get_transcription_job(job_name)39 status = response['TranscriptionJob']['TranscriptionJobStatus']40 if status == 'COMPLETED':41 break42 time.sleep(5)43 job_file_name = job_name + '.json'44 download_file(bucket_name, job_file_name, job_file_name)45 job_file_name = '20200307-051324-news_mp3.json'46 f = open(job_file_name, 'r', encoding="utf-8")47 json_dict = json.load(f)...
aws_interact.py
Source: aws_interact.py
...16 MediaFormat='mp3',17 LanguageCode='en-US'18 )19 while True:20 status = transcribe.get_transcription_job(21 TranscriptionJobName=job_name)22 if status['TranscriptionJob']['TranscriptionJobStatus'] in ['COMPLETED', 'FAILED']:23 break24 print('Translating audio...')25 time.sleep(5)26 response_url = transcribe.get_transcription_job(TranscriptionJobName=transcribe_job_name)27 translated_file_url = response_url['TranscriptionJob']['Transcript']['TranscriptFileUri']28 return translated_file_url29 def _download_from_url(self, url, local_output_path):30 with urllib.request.urlopen(url) as response, open(local_output_path, 'wb') as out_file:...
Check out the latest blogs from LambdaTest on this topic:
The fact is not alien to us anymore that cross browser testing is imperative to enhance your application’s user experience. Enhanced knowledge of popular and highly acclaimed testing frameworks goes a long way in developing a new app. It holds more significance if you are a full-stack developer or expert programmer.
QA testers have a unique role and responsibility to serve the customer. Serving the customer in software testing means protecting customers from application defects, failures, and perceived failures from missing or misunderstood requirements. Testing for known requirements based on documentation or discussion is the core of the testing profession. One unique way QA testers can both differentiate themselves and be innovative occurs when senseshaping is used to improve the application user experience.
Having a good web design can empower business and make your brand stand out. According to a survey by Top Design Firms, 50% of users believe that website design is crucial to an organization’s overall brand. Therefore, businesses should prioritize website design to meet customer expectations and build their brand identity. Your website is the face of your business, so it’s important that it’s updated regularly as per the current web design trends.
Enterprise resource planning (ERP) is a form of business process management software—typically a suite of integrated applications—that assists a company in managing its operations, interpreting data, and automating various back-office processes. The introduction of a new ERP system is analogous to the introduction of a new product into the market. If the product is not handled appropriately, it will fail, resulting in significant losses for the business. Most significantly, the employees’ time, effort, and morale would suffer as a result of the procedure.
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!!