473,466 Members | 1,320 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

interactive programme (voice)

hi i have wrote an interactive programme,this is a small section of it.
#This is my first programme writing in python
s = raw_input ("hello what's your name? ")
if s=='carmel':
print "Ahh the boss's wife"
if s=='melvyn':
print "your the boss's dad"
if s=='rebecca':
print "you must be the wreath woman"
if s=='gareth ':
print "You must be the trucker"
if s=='carol':
print "you must be my boss's mom"

What i was wandering is there a way i can get sound,i mean instead of getting
it to just print text on my screen i would like my computer to say it.
Thanks nige

May 30 '06 #1
1 1258
nigel a écrit :
hi i have wrote an interactive programme,this is a small section of it.
#This is my first programme writing in python
s = raw_input ("hello what's your name? ")
if s=='carmel':
print "Ahh the boss's wife"
if s=='melvyn':
print "your the boss's dad"
if s=='rebecca':
print "you must be the wreath woman"
if s=='gareth ':
print "You must be the trucker"
if s=='carol':
print "you must be my boss's mom"
The problem with this code is that:
- it does a lots of useless tests (ie : even if the user enters
'carmel', all other names will be tested too).
- it doesn't handle the default case (any other name than the one you
test for)

A minimal amelioration would be to use if/elif/else:
s = raw_input ("hello what's your name? ")
if s == 'carmel':
print "Ahh the boss's wife"
elif s == 'melvyn':
print "your the boss's dad"
elif s == 'rebecca':
print "you must be the wreath woman"
elif s == 'gareth ':
print "You must be the trucker"
elif s=='carol':
print "you must be my boss's mom"
else: # default
print "I'm afraid I don't know you..."

Now this is a little better, but still not very pythonic. We have a nice
thing in Python named a dict (for 'dictionnary'). It stores pairs of
key:value - and FWIW, it's the central data structure in Python, so
you'll see them quite a lot. There very handy for this kind of use case:

greetings = {
'carmel' : "Ahh the boss's wife",
'melvyn' : "your the boss's dad",
'rebecca': "you must be the wreath woman",
'gareth ': "You must be the trucker",
'carol' : "you must be my boss's mom",
}

name = raw_input ("hello what's your name? ")
print greetings.get(name, "I'm afraid I don't know you...")
What i was wandering is there a way i can get sound,
<sorry>
Now this is a sound question !-)
</sorry>
i mean instead of getting
it to just print text on my screen i would like my computer to say it.


This depends mostly on your computer and what's installed on it. And
this is not part of the standard lib AFAIK.
May 30 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: cm012b5105 | last post by:
Hello i want to put an interactive text programme in to a graphical box this is a small section of my text programme s = raw_input ("Hello whats your name? ") if s=='melvyn': print "your my...
14
by: Matt | last post by:
Any progammers looking for a killer app to develop? How about a voice enabled forum? One of the most powerful, exciting, and engrossing experiences on the Internet is the Forum. The first great...
1
by: Suhail A, Salman | last post by:
Dear All, we are planning to build voice applications or "IVRs: Interactive Voice Response applications" under .NET, any one knows what is the best technolohy/tools available and if you can...
5
by: Mad Scientist Jr | last post by:
I'm trying to record a voice memo on a Pocket PC (2000) from VB.NET (smart device application from vs.net 2003). Tom Shelton did an initial conversion to VB.NET which I am trying to run, but am...
1
by: cm012b5105 | last post by:
Hello i am fairly new to python, I have written an interactive programme a small example of it is here. s = raw_input ("Do you have any children? ") if s== 'yes': print "Thats great" elif...
1
by: nigel | last post by:
somebody recently showed me how to create a new line using \n which was great.The thing is when i am creating the programme the text i wish to add is quite long.and it ends up stretching the width...
0
by: carmel stanley | last post by:
Hi i have been making an interactive programme,i have recently tried using "pyTTS" with it. This is a small ammount of it. import pyTTS tts = pyTTS.Create() tts.Rate = -3 tts.Speak('hi...
20
by: Xavoux | last post by:
Hello all... I can't remind which function to use for safe inputs... gets, fgets, scanf leads to buffer overflow... i compiled that code with gcc version 2.95.2, on windows 2000 char tmp0 =...
2
by: patr0805 | last post by:
Hi I have created a voice regnocnition program but I can't get it to work. The problem comes when my program comes to the command: VoiceCmd.Initialized = 1. It says access denied exception from...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.