def test_message():
    endpoint = '/v2/assistants/{0}/sessions/{1}/message'.format(
        'bogus_id', 'session_id')
    url = '{0}{1}'.format(base_url, endpoint)
    response = {
        'output': {
            'generic': [{
                'text':
                'I did not understand that. I can help you get pizza, tell a joke or find a movie.',
                'response_type': 'text'
            }],
            'entities': [],
            'intents': [{
                'confidence': 0.8521236419677736,
                'intent': 'Weather'
            }]
        }
    }
    responses.add(responses.POST,
                  url,
                  body=json.dumps(response),
                  status=200,
                  content_type='application/json')
    service = watson_developer_cloud.AssistantV2(username='******',
                                                 password='******',
                                                 version='2017-02-03')
    message = service.message('bogus_id',
                              'session_id',
                              input={
                                  'text': 'What\'s the weather like?'
                              }).get_result()
    assert len(responses.calls) == 1
    assert responses.calls[0].request.url.startswith(url)
    assert message == response
def create_assistant():
    global assistant

    assistant = watson_developer_cloud.AssistantV2(
        username='******',
        password='******',
        version='2018-07-10',
        url='https://gateway.watsonplatform.net/assistant/api')
    assistant.set_detailed_response(True)
def test_create_session():
    endpoint = '/v2/assistants/{0}/sessions'.format('bogus_id')
    url = '{0}{1}'.format(base_url, endpoint)
    response = {'session_id': 'session_id'}
    responses.add(responses.POST,
                  url,
                  body=json.dumps(response),
                  status=200,
                  content_type='application/json')
    service = watson_developer_cloud.AssistantV2(username='******',
                                                 password='******',
                                                 version='2017-02-03')
    session = service.create_session('bogus_id').get_result()
    assert len(responses.calls) == 1
    assert responses.calls[0].request.url.startswith(url)
    assert session == response
Example #4
0
# Samantha Eng

import watson_developer_cloud

# Set up Assistant service.
service = watson_developer_cloud.AssistantV2(
    version='2018-09-20',
    username='******',
    password='******'  #replace with API Key
)

assistant_id = '4cde2101-84d4-460b-bbb1-bac49e5ce061'  # replace with assistant ID

# Create session.
session_id = service.create_session(
    assistant_id=assistant_id).get_result()['session_id']

user_input = ''
print("To leave the conversation with Jenny311, say 'bye' !")
while user_input != 'bye':
    response = service.message(assistant_id,
                               session_id,
                               input={
                                   'text': user_input
                               }).get_result()

    print(response['output']['generic'][0]['text'])

    user_input = input('>> ')
print("Thanks for chatting with Jenny311!")
# We're done, so we delete the session.
Example #5
0
import speech_recognition as sr
import watson_developer_cloud
from toca_musica import Playlist
from comandos_e_automatizacoes import Comandos
from respostas import Resposta
from watson_developer_cloud import AssistantV2

#
### CONFIGS ###
hotword = 'talu'  #Bot name
with open('{YOUR_GOOGLE_API}') as credenciais_google:
    credenciais_google = credenciais_google.read()

#Conect to Watson Assistant
service = watson_developer_cloud.AssistantV2(
    iam_apikey='{YOUR_API_KEY}',
    version='2018-11-08',
    url='https://gateway.watsonplatform.net/assistant/api')
assistant_id = '{YOUR_ASSISTANT_ID}'

response = service.create_session(assistant_id=assistant_id).get_result()


class Monitora():
    def monitora_audio(self):
        while True:
            microfone = sr.Recognizer()

            with sr.Microphone() as source:
                print("\nEsperando o comando...")  #Wait a command
                audio = microfone.listen(source)
import json
import watson_developer_cloud


ASSISTANT_ID="<Enter your ASSISTANT_ID>"



assistant = watson_developer_cloud.AssistantV2(
    iam_apikey='<Enter your API key>',
    version='2018-11-08',
    url='<Enter your assistant url that you set while creating the assistant>'# eg:'https://gateway-lon.watsonplatform.net/assistant/api' for london server
)


#creates a session with the api
session = assistant.create_session("ASSISTANT_ID").get_result()
print(json.dumps(session, indent=2))



#send your query to the api
#response variable recieves the json object with the response from api and the intent and extent detected
response = assistant.message(
    assistant_id='ASSISTANT_ID',
    session_id=session["session_id"],
    input={
        'message_type': 'text',
        'text': 'When are you open'            
    }
Example #7
0
        user = creds['username']
        password = creds['password']
        url = 'https://' + creds['host']
        client = Cloudant(user, password, url=url, connect=True)
        db = client.create_database(db_name, throw_on_exists=False)
        appi_db = client.create_database(applications_db,
                                         throw_on_exists=False)

# On IBM Cloud Cloud Foundry, get the port number from the environment variable PORT
# When running this app on the local machine, default the port to 8000
port = int(os.getenv('PORT', 8000))

# Initialising IBM Services

service = watson_developer_cloud.AssistantV2(
    iam_apikey='4ZTQ5aq-73YVWgTe2LMOlnMD_U580-6EnJZQKjAw9q6j',
    version='2018-11-08',
    url='https://gateway-lon.watsonplatform.net/assistant/api')

discovery = DiscoveryV1(
    version="2019-01-01",
    iam_apikey='Kw54FJSoj89aoZePeYMKusCWHE9phIRtJF1OQ64JTYmm',
    url="https://gateway-lon.watsonplatform.net/discovery/api")

# tone_analyzer = ToneAnalyzerV3(
#     version='2017-09-21',
#     iam_apikey='nmaZeOH66dY03tb8ctOIalQW9q1oylEIxC1XzbkC8wUj',
#     url='https://gateway-lon.watsonplatform.net/tone-analyzer/api'
# )

# checking issue affecting the functionality on the cloud
tone_analyzer = ToneAnalyzerV3(
Example #8
0
from google.cloud import speech
from google.cloud.speech import enums
from google.cloud.speech import types

from google.cloud import texttospeech
import watson_developer_cloud

import matplotlib.pyplot as plt

# loading json and creating model
# from keras.models import model_from_json

bp = Blueprint('view', __name__)

service = watson_developer_cloud.AssistantV2(
    iam_apikey='d7Gfh-2Zlm0vOGKjz067jZtTx8yM8C6Y0vrMmwH_05VT',
    version='2018-11-08',
    url='https://gateway.watsonplatform.net/assistant/api')

# json_file = open('model.json', 'r')
# loaded_model_json = json_file.read()
# json_file.close()
# loaded_model = model_from_json(loaded_model_json)
# # load weights into new model
# loaded_model.load_weights("saved_models/Emotion_Voice_Detection_Model.h5")
# print("Loaded model from disk")


@bp.route('/api/speech_to_text', methods=['GET'])
def speech_to_text():

    print('button pressed')