Advertisement
Guest User

Untitled

a guest
Mar 6th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. import requests
  2. import json
  3. import os
  4.  
  5. url = "https://stream.watsonplatform.net/speech-to-text-beta/api/v1/recognize"
  6. username= "USERNAME"
  7. password= "PASSWORD"
  8.  
  9. filepath = '/home/user/myfamily.ogg' # path to file
  10. filename = os.path.basename(filepath)
  11.  
  12. audio = open(filepath,'rb')
  13.  
  14. files_input = {
  15. "audioFile":(filename,audio,'audio/ogg')
  16. }
  17.  
  18. response = requests.post(url, auth=(username, password), headers={"Content-Type": "audio/wav"},files=files_input)
  19.  
  20. print('stauts_code: {} (reason: {})'.format(response.status_code, response.reason))
  21.  
  22. print response.text
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement