Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added bash_tests #141

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
62 changes: 62 additions & 0 deletions bash_tests/.gitignore
@@ -0,0 +1,62 @@
# config file
config.js

# Logs
logs
*.log
npm-debug.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Typescript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

# .DS_Store files
.DS_Store
67 changes: 67 additions & 0 deletions bash_tests/README.md
@@ -0,0 +1,67 @@
## Bash Scripts to test Watson AI Services

This folder contains bash scripts that are using **curl** command to call Watson APIs as explained on Watson getting started pages.

Test whether **curl** is installed. Run the following command on the command line.

```bash
curl -V
```

If the output lists the curl version with SSL support, you are all set otherwise install it.

```bash
sudo apt install curl
```
To run a script,
* change to the folder where you have the scripts:
```bash
cd ~/TJBOT/bash_tests
```
* type **./** followed by the name of script file then space then your api-key for the related service

```bash
./tone_analyzer_4.sh pomy6gsgO4kmjtNa3eiuhg7haziujhyf0Ps8WxTrIom6
mkhuthir marked this conversation as resolved.
Show resolved Hide resolved
```

example output:

```json
{"utterances_tone":[

{"utterance_id":0,
"utterance_text":"Hello, I'm having a problem with your product.",
"tones":[{ "score":0.686361,
"tone_id":"polite",
"tone_name":"Polite"}]},

{"utterance_id":1,
"utterance_text":"OK, let me know what's going on, please.",
"tones":[{ "score":0.92724,
"tone_id":"polite",
"tone_name":"Polite"}]},

{"utterance_id":2,"utterance_text":"Well, nothing is working :(",
"tones":[{ "score":0.997795,
"tone_id":"sad",
"tone_name":"Sad"}]},

{"utterance_id":3,"utterance_text":"Sorry to hear that.",
"tones":[{ "score":0.730982,
"tone_id":"polite",
"tone_name":"Polite"},

{ "score":0.672499,
"tone_id":"sympathetic",
"tone_name":"Sympathetic"}]}
]
}
```

Please note the following:

* api-key is the only parameter that you need to pass to the script
* script output will be either text in json format or a file that will be written to a subfolder
* scripts are modified version from what is given by Watson getting started to make it easier to understand
* service URLs are embedded inside the script, you might need to change it if you are using different service version
* you can get more details/help/examples on Watson Portal.
6 changes: 6 additions & 0 deletions bash_tests/hw_bluetooth_speaker.sh
@@ -0,0 +1,6 @@
#!/bin/sh

# the following will send test.wav file to bluetooth speaker.
# you need to change the AMC address to match your actual bluetooth speaker MAC

aplay -D bluealsa:HCI=hci0,DEV=11:2C:33:A4:1E:5B,PROFILE=a2dp speech/test.wav
mkhuthir marked this conversation as resolved.
Show resolved Hide resolved
4 changes: 4 additions & 0 deletions bash_tests/json/tone.json
@@ -0,0 +1,4 @@
{
"text": "This is an amazing demo full of examples."
}

20 changes: 20 additions & 0 deletions bash_tests/json/tone_chat.json
@@ -0,0 +1,20 @@
{
"utterances": [
{
"text": "Hello, I'm having a problem with your product.",
"user": "customer"
},
{
"text": "OK, let me know what's going on, please.",
"user": "agent"
},
{
"text": "Well, nothing is working :(",
"user": "customer"
},
{
"text": "Sorry to hear that.",
"user": "agent"
}
]
}
53 changes: 53 additions & 0 deletions bash_tests/json/tone_chat_output.json
@@ -0,0 +1,53 @@
{
"utterances_tone": [
{
"utterance_id": 0,
"utterance_text": "Hello, I'm having a problem with your product.",
"tones": [
{
"score": 0.686361,
"tone_id": "polite",
"tone_name": "Polite"
}
]
},
{
"utterance_id": 1,
"utterance_text": "OK, let me know what's going on, please.",
"tones": [
{
"score": 0.92724,
"tone_id": "polite",
"tone_name": "Polite"
}
]
},
{
"utterance_id": 2,
"utterance_text": "Well, nothing is working :(",
"tones": [
{
"score": 0.997795,
"tone_id": "sad",
"tone_name": "Sad"
}
]
},
{
"utterance_id": 3,
"utterance_text": "Sorry to hear that.",
"tones": [
{
"score": 0.730982,
"tone_id": "polite",
"tone_name": "Polite"
},
{
"score": 0.672499,
"tone_id": "sympathetic",
"tone_name": "Sympathetic"
}
]
}
]
}
3 changes: 3 additions & 0 deletions bash_tests/json/tone_sentence.json
@@ -0,0 +1,3 @@
{
"text": "Team, I know that times are tough! Product sales have been disappointing for the past three quarters. We have a competitive product, but we need to do a better job of selling it!"
}
15 changes: 15 additions & 0 deletions bash_tests/language_translator_1.sh
@@ -0,0 +1,15 @@
#!/bin/sh

# The following will translate two phrases, "Hello, world!" and "How are you?" from English to Spanish.

echo "Translate two phrases from English to Spanish"

if test "$#" -ne 1; then
echo "Usage: $0 api-key"
mkhuthir marked this conversation as resolved.
Show resolved Hide resolved
else
echo " Calling Watson Service API Using -> \"apikey:$1\""
curl -X POST -u "apikey:$1" \
--header "Content-Type: application/json" \
--data "{\"text\": [\"Hello, world! \", \"How are you?\"], \"model_id\":\"en-es\"}" \
"https://gateway-lon.watsonplatform.net/language-translator/api/v3/translate?version=2018-05-01"
mkhuthir marked this conversation as resolved.
Show resolved Hide resolved
fi
15 changes: 15 additions & 0 deletions bash_tests/language_translator_2.sh
@@ -0,0 +1,15 @@
#!/bin/sh

# The following will identify the language of text

echo "Identify the language of text"

if test "$#" -ne 1; then
echo "Usage: $0 api-key"
else
echo " Calling Watson Service API Using -> \"apikey:$1\""
curl -X POST -u "apikey:$1" \
--header "Content-Type: text/plain" \
--data "Language Translator translates text from one language to another" \
"https://gateway-lon.watsonplatform.net/language-translator/api/v3/identify?version=2018-05-01"
fi
Binary file added bash_tests/speech/audio-file.flac
Binary file not shown.
Binary file added bash_tests/speech/hello_world.ogg
Binary file not shown.
Binary file added bash_tests/speech/hello_world.wav
Binary file not shown.
6 changes: 6 additions & 0 deletions bash_tests/speech/hola_mundo.wav
@@ -0,0 +1,6 @@

{
"error": "No such child resource.",
"code": 404,
"code_description": "No Such Resource"
}
Binary file added bash_tests/speech/test.wav
Binary file not shown.
17 changes: 17 additions & 0 deletions bash_tests/speech_to_text_1.sh
@@ -0,0 +1,17 @@
#!/bin/sh

# Transcribe audio with no options
# The example uses the Content-Type header to indicate the type of the audio, audio/flac.
# The example uses the default language model, en-US_BroadbandModel, for transcription.

echo "Transcribe audio with no options"

if test "$#" -ne 1; then
echo "Usage: $0 api-key"
else
echo " Calling Watson Service API Using -> \"apikey:$1\""
curl -X POST -u "apikey:$1" \
--header "Content-Type: audio/flac" \
--data-binary @speech/audio-file.flac \
"https://gateway-lon.watsonplatform.net/speech-to-text/api/v1/recognize"
fi
19 changes: 19 additions & 0 deletions bash_tests/speech_to_text_2.sh
@@ -0,0 +1,19 @@
#!/bin/sh

# Transcribe audio with options
# Set the timestamps parameter to true to indicate the beginning and end of each word in the audio stream.
# Set the max_alternatives parameter to 3 to receive the three most likely alternatives for the transcription.
# The example uses the Content-Type header to indicate the type of the audio, audio/flac.
# The request uses the default model, en-US_BroadbandModel.

echo "Transcribe audio with options"

if test "$#" -ne 1; then
echo "Usage: $0 api-key"
else
echo " Calling Watson Service API Using -> \"apikey:$1\""
curl -X POST -u "apikey:$1" \
--header "Content-Type: audio/flac" \
--data-binary @speech/audio-file.flac \
"https://gateway-lon.watsonplatform.net/speech-to-text/api/v1/recognize?timestamps=true&max_alternatives=3"
fi
19 changes: 19 additions & 0 deletions bash_tests/text_to_speech_1.sh
@@ -0,0 +1,19 @@
#!/bin/sh

# Synthesize text in US English
# Synthesize the string "hello world" and produce a WAV file that is named hello_world.wav
# Request uses the default US English voice, en-US_MichaelVoice

echo "Synthesize text in US English"

if test "$#" -ne 1; then
echo "Usage: $0 api-key"
else
echo " Calling Watson Service API Using -> \"apikey:$1\""
curl -X POST -u "apikey:$1" \
--header "Content-Type: application/json" \
--header "Accept: audio/wav" \
--data "{\"text\":\"hello world\"}" \
--output ./speech/hello_world.wav \
"https://gateway-lon.watsonplatform.net/text-to-speech/api/v1/synthesize"
fi
19 changes: 19 additions & 0 deletions bash_tests/text_to_speech_2.sh
@@ -0,0 +1,19 @@
#!/bin/sh

# Synthesize text in US English
# Synthesize the string "hello world" and produce a WAV file that is named hello_world.ogg
# Request uses the default US English voice, en-US_MichaelVoice

echo "Synthesize text in US English"

if test "$#" -ne 1; then
echo "Usage: $0 api-key"
else
echo " Calling Watson Service API Using -> \"apikey:$1\""
curl -X POST -u "apikey:$1" \
--header "Content-Type: application/json" \
--header "Accept: audio/wav" \
--data "{\"text\":\"hello world\"}" \
--output ./speech/hello_world.ogg \
"https://gateway-lon.watsonplatform.net/text-to-speech/api/v1/synthesize"
fi
18 changes: 18 additions & 0 deletions bash_tests/text_to_speech_3.sh
@@ -0,0 +1,18 @@
#!/bin/sh

# Synthesize text in Spanish
# Synthesize the string "hola mundo" and produce a WAV file that is named hola_mundo.wav
# The input text is URL-encoded.
# The method includes the query parameter accept to specify the audio format
# The method includes the query parameter voice to specify a Spanish voice, es-ES_EnriqueVoice.

echo "Synthesize text in Spanish"

if test "$#" -ne 1; then
echo "Usage: $0 api-key"
else
echo " Calling Watson Service API Using -> \"apikey:$1\""
curl -X GET -u "apikey:$1" \
--output ./speech/hola_mundo.wav \
"https://gateway-lon.watsonplatform.net/text-to-speech/api/v1/synthesize\?accept=audio%2Fwav&text=hola%20mundo&voice=es-ES_EnriqueVoice"
fi
19 changes: 19 additions & 0 deletions bash_tests/tone_analyzer_1.sh
@@ -0,0 +1,19 @@
#!/bin/sh

# Analyze the contents tone of the file tone.json
# Using the general-purpose endpoint via the POST request method
# The file includes a single paragraph of plain text that is written by one person.
# Issue the following command to analyze the tone of the overall content and of each individual sentence.

echo "Analyze the contents tone of the file tone.json"

if test "$#" -ne 1; then
echo "Usage: $0 api-key"
else
echo " Calling Watson Service API Using -> \"apikey:$1\""
curl -X POST -u "apikey:$1" \
--header "Content-Type: application/json" \
--data-binary @./json/tone.json \
"https://gateway-lon.watsonplatform.net/tone-analyzer/api/v3/tone?version=2017-09-21"

fi