Skip to content

Instantly share code, notes, and snippets.

@PandaWhoCodes
Created December 21, 2016 04:48
Show Gist options
  • Save PandaWhoCodes/1c079def5519ba4feea327abc9458eca to your computer and use it in GitHub Desktop.
Save PandaWhoCodes/1c079def5519ba4feea327abc9458eca to your computer and use it in GitHub Desktop.
API.AI example explaination on bluescreen.club
!/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()
@sahilmodak1
Copy link

Hey,

How to I interact with api.ai using speech via a microphone in python?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment