def getSttToken(): try: data = request.form.get('data') authorization = Authorization(username=speachtotextUser, password=speachtotextPassword) retvalue = authorization.get_token(url=SpeechToText.default_url) except Exception as e: print(e) return retvalue
def getTtsToken(): try: data = request.form.get('data') authorization = Authorization(username=texttospeachUser, password=texttospeachPassword) retvalue = authorization.get_token(url=TextToSpeech.default_url) except Exception as e: print(e) return retvalue
def getTtsToken(): if (TTS_APIKEY): iamTokenManager = IAMTokenManager(iam_apikey=TTS_APIKEY) token = iamTokenManager.get_token() else: authorization = Authorization(username=TTS_USERNAME, password=TTS_PASSWORD) token = authorization.get_token(url=TTS_URL) return token
def get_token(request): """ Request watson service to get token for streaming service """ username = os.environ.get('username') password = os.environ.get('password') authorization = Authorization(username=username, password=password) return HttpResponse(authorization.get_token(url=SpeechToText.default_url), content_type='text/plain')
def getTtsToken(): try: authorization = AuthorizationV1(username=textToSpeechUser, password=textToSpeechPassword) retvalue = authorization.get_token(url=TextToSpeechV1.default_url) except Exception as e: print(e) return retvalue
def Authorize(): with open('watson.txt') as f: credentials = [x.strip().split(':') for x in f.readlines()] for username,password in credentials: authorization = AuthorizationV1( username=username, password=password) return credentials
def getSttToken(): try: authorization = AuthorizationV1(username=speechToTextUser, password=speechToTextPassword) retvalue = authorization.get_token(url=SpeechToTextV1.default_url) except Exception as e: print(e) return retvalue
def index(token=None): authorization = AuthorizationV1( username='******', password='******') # print(json.dumps(authorization.get_token(url=SpeechToTextV1.default_url), indent=2)) # token = json.dumps(authorization.get_token(url=SpeechToTextV1.default_url), indent=2) token = authorization.get_token(url=SpeechToTextV1.default_url) print(token) return render_template('index.html', token=token)
def __init__(self, name, data=None, secrets=SECRETS_FILE): try: if data is None: with open(secrets) as f: self.data = json.load(f)["watson"][name] else: self.data = data self.authorization = AuthorizationV1(**self.data) self.url = self.data["url"] except IOError: raise AuthenticationError("Failed to open secrets file") except KeyError: raise AuthenticationError("No credentials found for {}".format(name))
def run(self): print("Starting thread") auth = AuthorizationV1(username='******', password='******') token = auth.get_token( 'https://stream.watsonplatform.net/speech-to-text/api') url = '{0}?watson-token={1}&model={2}'.format(self.__URI__, token, 'pt-BR_NarrowbandModel') self.ws = websocket.WebSocketApp(url, on_open=self.on_open, on_message=self.on_message, on_error=self.on_error, on_close=self.on_close) self.ws.keep_running = True self.ws.daemon = True self.ws.run_forever()
import json from watson_developer_cloud import AuthorizationV1 from watson_developer_cloud import TextToSpeechV1 # get credentials & authorize per https://www.ibm.com/watson/developercloud/doc/common/getting-started-credentials.html # & https://github.com/watson-developer-cloud/python-sdk/tree/master/examples authorization = AuthorizationV1(username='******', password='******') text_to_speech = TextToSpeechV1(username='******', password='******', x_watson_learning_opt_out=True) # loop thru list of cleaned posts counter = 0 for i in friend17clean: # skip blank entries if i != '': # assign post text to TextBlob object & retrieve polarity & subjectivity scores tempblob = tb(i) pol = tempblob.sentiment.polarity * 100 # multiply by 100 to scale float to integer percentage sub = tempblob.sentiment.subjectivity * 100 # various if else statements handle differing lengths of returned integer to truncate decimals if pol == 100: pitch = pol elif pol >= 0: pitch = str(pol)[0:2] elif pol == -100: pitch = str(pol)[0:4]
def getSttToken(): authorization = Authorization( username='******', password='******') return authorization.get_token(url=SpeechToText.default_url)
def getTtsToken(): authorization = Authorization(username=TTS_USERNAME, password=TTS_PASSWORD) return authorization.get_token(url=TextToSpeech.default_url)
def getSttToken(): print(STT_USERNAME) authorization = Authorization(username=STT_USERNAME, password=STT_PASSWORD) return authorization.get_token(url=SpeechToText.default_url)
import json from watson_developer_cloud import AuthorizationV1 from watson_developer_cloud import SpeechToTextV1 authorization = AuthorizationV1( username='******', password='******') print(json.dumps(authorization.get_token(url=SpeechToTextV1.default_url), indent=2))
def obtain_auth_token(self): STT_USERNAME = os.environ['STT_USERNAME'] # '<Speech to Text username>' STT_PASSWORD = os.environ['STT_PASSWORD'] # '<Speech to Text password>' authorization = Authorization(username=STT_USERNAME, password=STT_PASSWORD) return authorization.get_token(url=SpeechToText.default_url)
from twisted.python import log from twisted.internet import reactor import sys sys.path.append('../..') from shared import MessageQueue import urllib.parse DEBUG = True with open('watson_credentials.json') as f: credentials = json.loads(f.read()) if not credentials: exit('no credentials') api_base_url = credentials['url'] authorization = AuthorizationV1(username=credentials['username'], password=credentials['password']) token = authorization.get_token(url=api_base_url) def create_regognition_method_str(api_base_url): parsed_url = urllib.parse.urlparse(api_base_url) return urllib.parse.urlunparse(( "wss", parsed_url.netloc, parsed_url.path + "/v1/recognize", parsed_url.params, parsed_url.query, parsed_url.fragment, ))
import json from watson_developer_cloud import AuthorizationV1 as Authorization from watson_developer_cloud import SpeechToTextV1 as SpeechToText authorization = Authorization(username='******', password='******') print(json.dumps(authorization.get_token(url=SpeechToText.default_url), indent=2))
def checkForTimeout(): global TIME_SINCE_RESPONSE global TIME_AT_RESPONSE while True: TIME_SINCE_RESPONSE = time.time() - TIME_AT_RESPONSE if (TIME_SINCE_RESPONSE > TIMEOUT_LIMIT): logging.info("Timeout limit reached, restarting WS...") try: resetConnection() except Exception as e: logging.error("Could not reset connection: " + str(e)) TIME_AT_RESPONSE = time.time() authorization = AuthorizationV1(username=USERNAME, password=PASSWORD) token = authorization.get_token(url=SpeechToTextV1.default_url) ws = create_connection( 'wss://stream.watsonplatform.net/speech-to-text/api/v1/recognize?watson-token=' + token + '&model=en-US_BroadbandModel') ws.send( '{"action":"start","content-type":"audio/l16;rate=16000","interim_results":true,"inactivity_timeout":600}' ) t3 = threading.Thread(target=receiveAudio) t3.start() #t4 = threading.Thread(target=checkForTimeout) #t4.start() getMicData()