Basic Bash Talking AI Example
Page 1 of 1
Basic Bash Talking AI Example
To get this working install espeak
- Code:
sudo apt install -y espeak
Code:
- Code:
#!/bin/bash
#
# jnet.forumotion.com/t1523-basic-bash-talking-ai-example#2267
#
# (c) J~Net 2017
#
# Usage: ./talk.sh
#
#
#
clear
echo "What is your name?"
echo "What is your name?" | espeak
read name
echo "Hi $name, how are you?"
echo "Hi $name, how are you?" | espeak
read how
if [ "$how" = "good" ] || [ "$how" = "ok" ]
then
echo "Ok $name, I am happy you are $how"
echo "Ok $name, I am happy you are $how" | espeak
else
echo "Ok $name, Why are you $how"
echo "Ok $name, Why are you $how" | espeak
read why
fi
Make executable:
- Code:
sudo chmod +x *.sh
Run:
- Code:
./talk.sh
Re: Basic Bash Talking AI Example
Part 2
Code:
For this part to work you will need a folder called Apps and inside that folder you will also need a folder called Games
inside that Games folder you will need this file...
you will need to make it executable like the first file
Code:
- Code:
#!/bin/bash
#
# jnet.forumotion.com/t1523-basic-bash-talking-ai-example#2267
#
# (c) J~Net 2017
#
# Usage: ./talk.sh
#
#
#
clear
echo "What is your name?"
echo "What is your name?" | espeak
read name
echo "Hi $name, how are you?"
echo "Hi $name, how are you?" | espeak
read how
if [ "$how" = "good" ] || [ "$how" = "ok" ]
then
echo "Ok $name, I am happy you are $how"
echo "Ok $name, I am happy you are $how" | espeak
else
echo "Ok $name, Why are you $how"
echo "Ok $name, Why are you $how" | espeak
read why
echo "Ok $name, I hope $why gets sorted soon."
echo "Ok $name, I hope $why gets sorted soon." | espeak
fi
echo "Pick something to do..."
echo "Pick something to do...(Number)" | espeak
echo "1 Play a game"
read opts
echo "You have selected $opts"
echo "You have selected $opts" | espeak
if [ "$opts" = "1" ]
then
# Play a game...
bash Apps/Games/Guess_Number.sh
fi
For this part to work you will need a folder called Apps and inside that folder you will also need a folder called Games
inside that Games folder you will need this file...
- Code:
#!/usr/bin/bash
#
# Guess_Number.sh - guessing game in BASH (Bourne Again Shell)
#
# This is written to demonstrate this language versus the same program
# written in other languages.
#
# 17-Oct-2004 Brendan Gregg Created this.
# Updated By J~Net 2017
# jnet.forumotion.com/t1523-basic-bash-talking-ai-example#2267
#
scorefile="highscores_bash"
guess=-1
typeset -i num=0
echo -e "guess.bash - Guess a number between 1 and 100\n"
### Generate random number
(( answer = RANDOM % 100 + 1 ))
### Play game
while (( guess != answer )); do
num=num+1
echo "Choose a number" | espeak
read -p "Enter guess $num: " guess
if (( guess < answer )); then
echo "Higher..."
echo "Higher..." | espeak
elif (( guess > answer )); then
echo "Lower..."
echo "Lower..." | espeak
fi
done
echo -e "Correct! That took $num guesses.\n"
echo -e "Correct! That took $num guesses." | espeak
### Save high score
echo "Please enter your name for the scoreboard" | espeak
read -p "Please enter your name: " name
echo $name $num >> $scorefile
### Print high scores
echo "Previous high scores" | espeak
echo -e "\nPrevious high scores,"
cat $scorefile
you will need to make it executable like the first file
- Code:
sudo chmod +x *.sh
Re: Basic Bash Talking AI Example
Part 3
talk.sh now has a menu function for returning back from a game for example.
Updated Game
Guess_Number.sh
talk.sh now has a menu function for returning back from a game for example.
- Code:
#!/bin/bash
#
# jnet.forumotion.com/t1523-basic-bash-talking-ai-example#2267
#
# (c) J~Net 2017
#
# Usage: ./talk.sh
#
#
#
clear
echo "What is your name?"
echo "What is your name?" | espeak
read name
echo "Hi $name, how are you?"
echo "Hi $name, how are you?" | espeak
read how
if [ "$how" = "good" ] || [ "$how" = "ok" ]
then
echo "Ok $name, I am happy you are $how"
echo "Ok $name, I am happy you are $how" | espeak
else
echo "Ok $name, Why are you $how"
echo "Ok $name, Why are you $how" | espeak
read why
echo "Ok $name, I hope $why gets sorted soon."
echo "Ok $name, I hope $why gets sorted soon." | espeak
fi
# Menu Function
Menu () {
echo "Pick something to do..."
echo "Pick something to do...(Number)" | espeak
echo "1 Play a game"
read opts
echo "You have selected $opts"
echo "You have selected $opts" | espeak
if [ "$opts" = "1" ]
then
# Play a game...
bash Apps/Games/Guess_Number.sh $name
fi
}
Menu
echo "Welcome back"
echo "Welcome back" | espeak
Menu
Updated Game
Guess_Number.sh
- Code:
#!/usr/bin/bash
#
# Guess_Number.sh - guessing game in BASH (Bourne Again Shell)
#
# This is written to demonstrate this language versus the same program
# written in other languages.
#
# 17-Oct-2004 Brendan Gregg Created this.
# Updated By J~Net 2017
# jnet.forumotion.com/t1523-basic-bash-talking-ai-example#2267
#
name="$1"
scorefile="highscores_bash"
guess=-1
typeset -i num=0
echo -e "guess.bash - Guess a number between 1 and 100\n"
### Generate random number
(( answer = RANDOM % 100 + 1 ))
### Play game
while (( guess != answer )); do
num=num+1
echo "Choose a number" | espeak
read -p "Enter guess $num: " guess
if (( guess < answer )); then
echo "Higher..."
echo "Higher..." | espeak
elif (( guess > answer )); then
echo "Lower..."
echo "Lower..." | espeak
fi
done
echo -e "Correct! That took $num guesses.\n"
echo -e "Correct! That took $num guesses." | espeak
### Save high score
# echo "Please enter your name for the scoreboard" | espeak
# read -p "Please enter your name: " name
echo $name $num >> $scorefile
### Print high scores
echo "Previous high scores" | espeak
echo -e "\nPrevious high scores,"
cat $scorefile
Re: Basic Bash Talking AI Example
The Updated File Link
app.box.com/s/414qsmn2oei3lr014iw4bd50j7e9nvw8
Please Note: The aes file to be decrypted will need to be placed in the correct folder along with the script you choose to decrypt it!
Similar topics
» Basic Spelling Game With Bash & Aspell On Linux Mint Example
» Talking Countdown With Bash On Linux
» Linux Bash Talking Function
» BASH Linux Talking IP Script
» Talking Clock With Bash On Linux & espeak
» Talking Countdown With Bash On Linux
» Linux Bash Talking Function
» BASH Linux Talking IP Script
» Talking Clock With Bash On Linux & espeak
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum