-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
"""Example 2: STT - getVoice2Text """ | ||
|
||
from __future__ import print_function | ||
|
||
import grpc | ||
import os | ||
import datetime | ||
import hmac | ||
import hashlib | ||
|
||
|
||
# Config for GiGA Genie gRPC | ||
CLIENT_ID = "Y2xpZW50X2lkMTYyNTI5NTUxMzQyOQ==" #'Y2xpZW50X2lkMTYyNTEzMzk5NzU2NA=='#'Y2xpZW50X2lkMTYyNTAyNzcyMTA5Nw=='# | ||
CLIENT_KEY = "Y2xpZW50X2tleTE2MjUyOTU1MTM0Mjk=" #'Y2xpZW50X2tleTE2MjUxMzM5OTc1NjQ='#'Y2xpZW50X2tleTE2MjUwMjc3MjEwOTc='# | ||
CLIENT_SECRET = "Y2xpZW50X3NlY3JldDE2MjUyOTU1MTM0Mjk=" #'Y2xpZW50X3NlY3JldDE2MjUwMjc3MjEwOTc='# "Y2xpZW50X3NlY3JldDE2MjUyOTU1MTM0Mjk=" | ||
|
||
|
||
### COMMON : Client Credentials ### | ||
def getMetadata(): | ||
timestamp = datetime.datetime.now().strftime("%Y%m%d%H%M%S%f")[:-3] | ||
message = CLIENT_ID + ':' + timestamp | ||
|
||
signature = hmac.new(CLIENT_SECRET.encode(), message.encode(), hashlib.sha256).hexdigest() | ||
|
||
metadata = [('x-auth-clientkey', CLIENT_KEY), | ||
('x-auth-timestamp', timestamp), | ||
('x-auth-signature', signature)] | ||
|
||
return metadata | ||
|
||
def credentials(context, callback): | ||
callback(getMetadata(), None) | ||
|
||
def getCredentials(): | ||
sslCred = grpc.ssl_channel_credentials() | ||
authCred = grpc.metadata_call_credentials(credentials) | ||
return grpc.composite_channel_credentials(sslCred, authCred) | ||
|
||
### END OF COMMON ### |