Created
December 21, 2016 04:48
-
-
Save PandaWhoCodes/1c079def5519ba4feea327abc9458eca to your computer and use it in GitHub Desktop.
API.AI example explaination on bluescreen.club
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
!/usr/bin/env python | |
-*- coding: utf-8 -*- | |
import os.path | |
import sys | |
import json | |
try: | |
import apiai | |
except ImportError: | |
sys.path.append( | |
os.path.join(os.path.dirname(os.path.realpath(__file__)), os.pardir) | |
) | |
import apiai | |
CLIENT_ACCESS_TOKEN = 'your client access token' | |
def main(): | |
while(1): | |
ai = apiai.ApiAI(CLIENT_ACCESS_TOKEN) | |
request = ai.text_request() | |
request.lang = 'en' # optional, default value equal 'en' | |
# request.session_id = "<SESSION ID, UBIQUE FOR EACH USER>" | |
print("\n\nYour Input : ",end=" ") | |
request.query = input() | |
print("\n\nBot\'s response :",end=" ") | |
response = request.getresponse() | |
responsestr = response.read().decode('utf-8') | |
response_obj = json.loads(responsestr) | |
print(response_obj["result"]["fulfillment"]["speech"]) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey,
How to I interact with api.ai using speech via a microphone in python?