Skip to content

Commit

Permalink
Generate Text to Speech (watson-developer-cloud#332)
Browse files Browse the repository at this point in the history
* 🆕 generated text-to-speech with latest swagger

* 💚 added missing tests and updated method names in tests

* Changes as per review Mike's comments

* Remove unnecessary overview

* 😒 Rename Bluemix to IBM Cloud

* change Bluemix to IBM Cloud

* fix capitalization of IBM CLoud

* Update README.md

* 📝 Update to use Watson APIs

* Adding integration tests and removing REST description

* enable dot_env to get env variables

* Revert "enable dot_env to get env variables"

This reverts commit f7ac60a.

* Encrypt travis env file

* Adding VCAP_SERVICES

* Ignoring destructive tests

* Remove the VCAP_SERVICES keyword

* Regenerate encrypted env file for travis

* Remove the skip test for integration test

* Add in init file for integration tests

* Update tests as per new env file
  • Loading branch information
ammardodin authored and germanattanasio committed Feb 9, 2018
1 parent 401efc1 commit ad44aac
Show file tree
Hide file tree
Showing 20 changed files with 1,402 additions and 393 deletions.
Binary file modified .env.enc
Binary file not shown.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ python:
- '3.6'
cache: pip
before_install:
- '[ "${TRAVIS_PULL_REQUEST}" = "false" ] && openssl aes-256-cbc -K $encrypted_6e98b3e8e789_key -iv $encrypted_6e98b3e8e789_iv -in .env.enc -out .env -d || true'
- '[ "${TRAVIS_PULL_REQUEST}" = "false" ] && openssl aes-256-cbc -K $encrypted_cebf25e6c525_key
-iv $encrypted_cebf25e6c525_iv -in .env.enc -out .env -d || true'
install: pip install tox-travis
script: tox
before_deploy:
Expand Down
21 changes: 9 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Watson Developer Cloud Python SDK

[![Build Status](https://travis-ci.org/watson-developer-cloud/python-sdk.svg)](https://travis-ci.org/watson-developer-cloud/python-sdk)
[![Build Status](https://travis-ci.org/watson-developer-cloud/python-sdk.svg?branch=master)](https://travis-ci.org/watson-developer-cloud/python-sdk)
[![Slack](https://wdc-slack-inviter.mybluemix.net/badge.svg)](https://wdc-slack-inviter.mybluemix.net)
[![codecov.io](https://codecov.io/github/watson-developer-cloud/python-sdk/coverage.svg?branch=master)](https://codecov.io/github/watson-developer-cloud/python-sdk?branch=master)
[![Latest Stable Version](https://img.shields.io/pypi/v/watson-developer-cloud.svg)](https://pypi.python.org/pypi/watson-developer-cloud)

Python client library to quickly get started with the various [Watson Developer Cloud][wdc] services.
Python client library to quickly get started with the various [Watson APIs][wdc] services.

## Installation

Expand Down Expand Up @@ -37,24 +37,24 @@ The [examples][examples] folder has basic and advanced examples.

Service credentials are required to access the APIs.

If you run your app in Bluemix, you don't need to specify the username and password. In that case, the SDK uses the `VCAP_SERVICES` environment variable to load the credentials.
If you run your app in IBM Cloud, you don't need to specify the username and password. In that case, the SDK uses the `VCAP_SERVICES` environment variable to load the credentials.

To run locally or outside of Bluemix you need the `username` and `password` credentials for each service. (Service credentials are different from your Bluemix account email and password.)
To run locally or outside of IBM Cloud you need the `username` and `password` credentials for each service. (Service credentials are different from your IBM Cloud account email and password.)

To create an instance of the service:

1. Log in to [Bluemix][bluemix].
1. Log in to [IBM Cloud][ibm_cloud].
1. Create an instance of the service:
1. In the Bluemix **Catalog**, select the Watson service you want to use. For example, select the Conversation service.
1. In the IBM Cloud **Catalog**, select the Watson service you want to use. For example, select the Conversation service.
1. Type a unique name for the service instance in the **Service name** field. For example, type `my-service-name`. Leave the default values for the other options.
1. Click **Create**.

To get your service credentials:

Copy your credentials from the **Service details** page. To find the the Service details page for an existing service, navigate to your Bluemix dashboard and click the service name.
Copy your credentials from the **Service details** page. To find the the Service details page for an existing service, navigate to your IBM Cloud dashboard and click the service name.

1. On the **Service Details** page, click **Service Credentials**, and then **View credentials**.
1. Copy `username` and `password`.
1. Copy `username`, `password`, and `url`.

## Python Version

Expand Down Expand Up @@ -82,9 +82,6 @@ response = conversation.message(workspace_id=workspace_id, input={
'text': 'What\'s the weather like?'})
print(json.dumps(response, indent=2))
```
## Known Issues

See [issues](https://github.com/watson-developer-cloud/python-sdk/issues).

## Dependencies

Expand All @@ -104,7 +101,7 @@ See [CONTRIBUTING.md][CONTRIBUTING].
This library is licensed under the [Apache 2.0 license][license].

[wdc]: http://www.ibm.com/watson/developercloud/
[bluemix]: https://console.bluemix.net
[ibm_cloud]: https://console.bluemix.net
[responses]: https://github.com/getsentry/responses
[requests]: http://docs.python-requests.org/en/latest/
[examples]: https://github.com/watson-developer-cloud/python-sdk/tree/master/examples
Expand Down
11 changes: 5 additions & 6 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
## Examples
To run the examples, you will need the `username` and `password` credentials. To get your service credentials, follow these steps:
1. Log in to Bluemix at https://bluemix.net.
To run the examples, you will need a `username`, `password`, and `url`. To get your service credentials, follow these steps:
1. Log in to IBM Cloud at https://console.bluemix.net.

1. Create an instance of the service:
1. In the Bluemix **Catalog**, select the Natural Language Classifier service.
1. Under **Add Service**, type a unique name for the service instance in the Service name field. For example, type `my-service-name`. Leave the default values for the other options.
1. Click **Use**.
1. In the IBM Cloud **Catalog**, select the Natural Language Classifier service.
1. Click **Create**.

1. Copy your credentials:
1. On the left side of the page, click **Service Credentials** to view your service credentials.
1. Copy `username` and `password` from these service credentials.
1. Copy `username`, `password`, and `url` from these service credentials.
8 changes: 4 additions & 4 deletions examples/conversation_tone_analyzer_integration/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ This example provides sample code for integrating [Tone Analyzer][tone_analyzer]

Requirements to run the sample code

* [Tone Analyzer Service credentials][bluemix_tone_analyzer_service]
* [Conversation Service credentials][bluemix_conversation_service]
* [Tone Analyzer Service credentials][ibm_cloud_tone_analyzer_service]
* [Conversation Service credentials][ibm_cloud_conversation_service]
* [Conversation Workspace ID][conversation_simple_workspace]

Credentials & the Workspace ID can be set in environment properties, a .env file, or directly in the code.
Expand All @@ -24,8 +24,8 @@ Command to run the sample code

[conversation]: https://www.ibm.com/watson/developercloud/conversation.html
[tone_analyzer]: http://www.ibm.com/watson/developercloud/tone-analyzer.html
[bluemix_conversation_service]: https://console.ng.bluemix.net/catalog/services/conversation/
[bluemix_tone_analyzer_service]: https://console.ng.bluemix.net/catalog/services/tone-analyzer/
[ibm_cloud_conversation_service]: https://console.ng.bluemix.net/catalog/services/conversation/
[ibm_cloud_tone_analyzer_service]: https://console.ng.bluemix.net/catalog/services/tone-analyzer/
[conversation_simple_workspace]: https://github.com/watson-developer-cloud/conversation-simple#workspace
[tone_conversation_integration_example]: https://github.com/watson-developer-cloud/python-sdk/tree/master/examples/tone_conversation_integration.v1.py
[tone_conversation_integration_example_tone_detection]: https://github.com/watson-developer-cloud/python-sdk/tree/master/examples/conversation_addons/tone_detection.py
Expand Down
18 changes: 5 additions & 13 deletions examples/conversation_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,11 @@
import os
from watson_developer_cloud import ConversationV1

#########################
# message
#########################

conversation = ConversationV1(
username='YOUR SERVICE USERNAME',
password='YOUR SERVICE PASSWORD',
version='2017-04-21')

# replace with your own workspace_id
workspace_id = '506e4a2e-3d5d-4dca-b374-38edbb4139ab'
if os.getenv("conversation_workspace_id") is not None:
workspace_id = os.getenv("conversation_workspace_id")

response = conversation.message(workspace_id=workspace_id, input={
'text': 'What\'s the weather like?'})
print(json.dumps(response, indent=2))

# When you send multiple requests for the same conversation, include the
# context object from the previous response.
# response = conversation.message(workspace_id=workspace_id, message_input={
Expand All @@ -43,6 +30,11 @@
response = conversation.get_workspace(workspace_id=workspace_id, export=True)
print(json.dumps(response, indent=2))

# message
response = conversation.message(workspace_id=workspace_id, input={
'text': 'What\'s the weather like?'})
print(json.dumps(response, indent=2))

response = conversation.list_workspaces()
print(json.dumps(response, indent=2))

Expand Down
49 changes: 0 additions & 49 deletions examples/dialog_v1.py

This file was deleted.

23 changes: 10 additions & 13 deletions examples/natural_language_classifier_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
# from os.path import join, dirname
from watson_developer_cloud import NaturalLanguageClassifierV1

# replace with your own classifier_id
classifier_id = 'e552ebx250-nlc-13834'
if os.getenv("natural_language_classifier_classifier_id") is not None:
classifier_id = os.getenv("natural_language_classifier_classifier_id")

natural_language_classifier = NaturalLanguageClassifierV1(
username='YOUR SERVICE USERNAME',
Expand All @@ -17,13 +13,14 @@
print(json.dumps(classifiers, indent=2))

# create a classifier
# with open('../resources/weather_data_train.csv', 'rb') as training_data:
# metadata = json.dumps({'name': 'my-classifier', 'language': 'en'})
# classifier = natural_language_classifier.create_classifier(
# metadata=metadata,
# training_data=training_data
# )
# print(json.dumps(classifier, indent=2))
with open(os.path.join(os.path.dirname(__file__), '../resources/weather_data_train.csv'), 'rb') as training_data:
metadata = json.dumps({'name': 'my-classifier', 'language': 'en'})
classifier = natural_language_classifier.create_classifier(
metadata=metadata,
training_data=training_data
)
classifier_id = classifier['classifier_id']
print(json.dumps(classifier, indent=2))

status = natural_language_classifier.get_classifier(classifier_id)
print(json.dumps(status, indent=2))
Expand All @@ -34,8 +31,8 @@
'tomorrow?')
print(json.dumps(classes, indent=2))

# delete = natural_language_classifier.delete_classifier('2374f9x68-nlc-2697')
# print(json.dumps(delete, indent=2))
delete = natural_language_classifier.delete_classifier(classifier_id)
print(json.dumps(delete, indent=2))

# example of raising a ValueError
# print(json.dumps(
Expand Down
79 changes: 0 additions & 79 deletions examples/retrieve_and_rank_v1.py

This file was deleted.

13 changes: 5 additions & 8 deletions examples/text_to_speech_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,19 @@

text_to_speech = TextToSpeechV1(
username='YOUR SERVICE USERNAME',
password='YOUR SERVICE PASSWORD',
x_watson_learning_opt_out=True) # Optional flag
password='YOUR SERVICE PASSWORD')

print(json.dumps(text_to_speech.voices(), indent=2))
print(json.dumps(text_to_speech.list_voices(), indent=2))

with open(join(dirname(__file__), '../resources/output.wav'),
'wb') as audio_file:
audio_file.write(
text_to_speech.synthesize('Hello world!', accept='audio/wav',
voice="en-US_AllisonVoice"))
voice="en-US_AllisonVoice").content)

print(
json.dumps(text_to_speech.pronunciation(
'Watson', pronunciation_format='spr'), indent=2))
print(json.dumps(text_to_speech.get_pronunciation('Watson', format='spr'), indent=2))

print(json.dumps(text_to_speech.customizations(), indent=2))
print(json.dumps(text_to_speech.list_voice_models(), indent=2))

# print(json.dumps(text_to_speech.create_customization('test-customization'),
# indent=2))
Expand Down
16 changes: 0 additions & 16 deletions examples/tradeoff_analytics_v1.py

This file was deleted.

4 changes: 4 additions & 0 deletions test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from dotenv import load_dotenv, find_dotenv

# load the .env file containing your environment variables for the required
load_dotenv(find_dotenv())
17 changes: 17 additions & 0 deletions test/integration/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2015 IBM All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from dotenv import load_dotenv, find_dotenv

# load the .env file containing your environment variables for the required
load_dotenv(find_dotenv())
File renamed without changes.
Loading

0 comments on commit ad44aac

Please sign in to comment.