Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from watson_developer_cloud import SpeechToTextV1 as SpeechToText
- # Use this method to send the audio to Watson and save the response
- def get_and_save_transcript(audio_file, transcript_file):
- with open(audio_file, 'rb') as af:
- resp = stt.recognize(af,
- content_type='audio/wav',
- timestamps=True,
- continuous=True,
- word_confidence=True,
- profanity_filter=False,
- word_alternatives_threshold=0.4)
- with open(transcript_file, 'w') as tf:
- tf.write(json.dumps(resp))
- stt = SpeechToText(
- username='<YOUR SERVICE USERNAME>',
- password='<YOUR SERVICE PASSWORD>')
- # Make a directory to save our transcripts
- if not os.path.exists(join(project_dir, 'split_transcripts')):
- os.makedirs(join(project_dir, 'split_transcripts'))
- trancription_jobs = []
- transcript_files = []
- # Create a new job for each audio segment
- for chunk in segment_files:
- transcript_file = '{}.json'.format(splitext(basename(chunk))[0])
- full_transcript_file = join(project_dir, 'split_transcripts', transcript_file)
- transcript_files.append(full_transcript_file)
- job = Process(target=get_and_save_transcript,
- args=(chunk,full_transcript_file))
- job.start()
- trancription_jobs.append(job)
- for job in trancription_jobs:
- job.join()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement