473,597 Members | 2,256 Online
Bytes | Software Development & Data Engineering Community
+ 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 1272
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(n ame, "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
1238
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 boss's Dad the one they call in indian language DEEP THOUGHT LITTLE HORSE" if s=='carol': print "ahhh you are my boss's mom the one they call WREATH WOMAN" if s=='rebecca':
14
3150
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 Internet forums were the Usenet newsgroups. Usenet is still a powerful force, but many different types of forums are also very popular (such as message boards like Vbulliten and XMBforum). I love forums. Love em love em love em. My web site...
1
2178
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 help me with some links that will be great.. thanks for helping
5
4672
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 getting errors I don't quite understand (I've never done anything like this before)... Any help would be appreciated in getting this to work... '-----------------------------------------------------------------------------
1
1863
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 s=='no': print "Well my boss has 2" Now i have also been looking at Tkinter if we take the basic "hello, world"
1
1675
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 of several pages,which i think looks quite messy.Would it be possible for some one to show me how to create another line while writing my programme.What i mean by this is where my text ends "iv arrived"i wish to add a new line beneath to continue...
0
1161
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 molly how old are you?.') s = raw_input ("how old are you?")
20
10995
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 = "ABCDEFGHI\0"; char buff; /* Input buffer. */ char tmp1 = "ABCDEFGHI\0";
2
3355
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 HRESULT: 0x80030005 (STG_E_ACCESSDENIED. Option Strict Off Option Explicit On Friend Class Frm_Voice_Command Inherits System.Windows.Forms.Form Private My_menu As Integer Private Loop_1 As Integer Private TCount As Integer
0
7884
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8267
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
6681
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5423
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3880
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3921
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2394
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 we have to send another system
1
1493
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1229
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.