[ Linkit Smart 7688 ] 透過 Python 取得 Microsoft 的 Cognitive Services Token

Microsoft 提供的雲端服務為數眾多,例如:Bing SpeechLanguage Understanding Intelligent ServiceText AnalyticsSpeaker Recognition,而本文使用 Microsoft 的 Cognitive Services 來取得 Token,以供後續服務使用。


前置準備作業

  1. 準備一片 Linkit Smart 7688 開發板

  2. 將 Linkit Smart 7688 連接至電腦

  3. 更新 Firmware 為 0.9.3
    http://goo.gl/dVLQ2Y

  4. 將 USB 音效卡透過 OTG Cable 安裝於 Linkit Smart 7688

  5. 安裝 MIC 與 Speaker 於外接 USB 音效卡上

  6. 安裝 USB 音效卡相關套件
    REF: http://goo.gl/D5rHtu


Linkit Smart 7688 與 USB 外接音效卡連接圖


Microsoft 端

Step 1. 到 Microsoft 網站申請帳號

https://www.microsoft.com/cognitive-services/


Step 2. 登入 Microsoft Cognitive Services 網站

https://www.microsoft.com/cognitive-services/


Step 3. 點擊 Get started for free


Step 4. 點選 Bing Speech - PreviewI agree to the Microsoft Cognitive Services Terms and Microsoft Privacy StatementSubscribe


Linkit Smart 7688 端

Step 1. SSH 進入 Linkit Smart 7688 中

Imgur


Step 2. 於 Linkit Smart 7688 中建立取得 Microsoft Token 的 Python Code
  • 更新 msBingSpeechAPIKey
import httplib, json, urllib

accessToken = ""  
wavBody = ""  
accessTokenHost = "api.cognitive.microsoft.com"  
tokenPath = "/sts/v1.0/issueToken"  
msBingSpeechAPIKey = "9b4c82c9b8c342aa8beac43cf33a12bc"

headers = {  
            "Content-type": "application/x-www-form-urlencoded",
            "Ocp-Apim-Subscription-Key": msBingSpeechAPIKey
        }

params = urllib.urlencode({})  
conn = httplib.HTTPSConnection(accessTokenHost)  
conn.request("POST", tokenPath, "", headers)  
response = conn.getresponse()  
accessToken = response.read()  
conn.close()  
print(response.status, response.reason, accessToken)


Step 3. 執行 Python Code
python get_token.py  


Github
參考資料
List of blogs

Archer

Having being a full stack engineer. Experience with C, Python, Objective-C, Swift, Node.js, Lua, Linkit Smart 7688, Raspberry Pi, ARM mbed, Arduino, IoT solutions. Contact us : [email protected]

ALL RIGHTS RESERVED. COPYRIGHT © 2016. Designed and Coded by Makee.io