Advertisement
Guest User

Untitled

a guest
Oct 11th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. from watson_developer_cloud import SpeechToTextV1 as SpeechToText
  2.  
  3. # Use this method to send the audio to Watson and save the response
  4. def get_and_save_transcript(audio_file, transcript_file):
  5. with open(audio_file, 'rb') as af:
  6. resp = stt.recognize(af,
  7. content_type='audio/wav',
  8. timestamps=True,
  9. continuous=True,
  10. word_confidence=True,
  11. profanity_filter=False,
  12. word_alternatives_threshold=0.4)
  13. with open(transcript_file, 'w') as tf:
  14. tf.write(json.dumps(resp))
  15.  
  16. stt = SpeechToText(
  17. username='<YOUR SERVICE USERNAME>',
  18. password='<YOUR SERVICE PASSWORD>')
  19.  
  20. # Make a directory to save our transcripts
  21. if not os.path.exists(join(project_dir, 'split_transcripts')):
  22. os.makedirs(join(project_dir, 'split_transcripts'))
  23.  
  24. trancription_jobs = []
  25. transcript_files = []
  26.  
  27. # Create a new job for each audio segment
  28. for chunk in segment_files:
  29. transcript_file = '{}.json'.format(splitext(basename(chunk))[0])
  30. full_transcript_file = join(project_dir, 'split_transcripts', transcript_file)
  31. transcript_files.append(full_transcript_file)
  32. job = Process(target=get_and_save_transcript,
  33. args=(chunk,full_transcript_file))
  34. job.start()
  35.  
  36. trancription_jobs.append(job)
  37.  
  38. for job in trancription_jobs:
  39. job.join()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement