473,700 Members | 2,743 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 1276
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
1246
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
3163
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
2180
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
4678
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
1867
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
1680
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
1166
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
11008
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
3363
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
8731
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8649
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
9082
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
6567
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5904
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
4410
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
4660
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3098
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
3
2032
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.