I am writing a python program on Windows using Python 2.7. Basically, it's a program that takes a 5-digit, negative & positive, number from user & spells it out in English using num2word & then speaks it out too. I have used espeak & pyttsx both but i'm getting errors in all of them. I have tried this: - num = raw_input('Please enter your 5 digit number:')
-
while len(num) != 5 or (not num.isdigit()):
-
print 'Not a 5 digit number'
-
num = raw_input('Please enter your 5 digit number:')
-
num = int(num)
-
-
def spellnum(num,join=True):
-
#Lists of number words
-
-
thousands = ['','thousand','million']
-
tens = ['','ten','twenty','thirty','forty','fifty','sixty','seventy','eighty','ninety']
-
teens = ['','eleven','twelve','thirteen','fourteen','fifteen','sixteen','seventeen','eighteen','nineteen']
-
units = ['','one','two','three','four','five','six','seven','eight','nine']
-
#Empty List for number words
-
words = []
-
#zero case
-
if num==0: words.append('zero')
-
#how to handle negative numbers
-
if num < 0: words.append('negative')
-
num = abs(num)
-
#a series of steps to process the numbers and turn them into words
-
numStr = '%d'%num
-
numStrLen = len(numStr)
-
groups = (numStrLen+2)/3
-
numStr = numStr.zfill(groups*3)
-
for i in range(0,groups*3,3):
-
h,t,u = int(numStr[i]),int(numStr[i+1]),int(numStr[i+2])
-
g = groups-(i/3+1)
-
if h>=1:
-
words.append(units[h])
-
words.append('hundred')
-
if t>1:
-
words.append(tens[t])
-
if u>=1: words.append(units[u])
-
elif t==1:
-
if u>=1: words.append(teens[u])
-
else: words.append(tens[t])
-
else:
-
if u>=1: words.append(units[u])
-
if (g>=1) and ((h+t+u)>0): words.append(thousands[g]+',')
-
#final joining of parts
-
if join: return ' '.join(words)
-
return words
-
-
print 'Your number is: ', spellnum(num)
-
-
import pyttsx
-
engine = pyttsx.init()
-
engine.setProperty('rate', 70)
-
-
voices = engine.getProperty('voices')
-
for voice in voices:
-
print "Using voice:", repr(voice)
-
engine.setProperty('voice', voice.id)
-
engine.say(spellnum(num))
-
engine.runAndWait()
-
Output was: - Please enter your 5 digit number:34342
-
Your number is: thirty four thousand,
-
-
Traceback (most recent call last):
-
File "C:\Python27\prj.py", line 48, in <module>
-
engine = pyttsx.init()
-
File "C:\Python27\lib\site-packages\pyttsx\__init__.py", line 39, in init
-
eng = Engine(driverName, debug)
-
File "C:\Python27\lib\site-packages\pyttsx\engine.py", line 45, in __init__
-
self.proxy = driver.DriverProxy(weakref.proxy(self), driverName, debug)
-
File "C:\Python27\lib\site-packages\pyttsx\driver.py", line 64, in __init__
-
self._module = __import__(name, globals(), locals(), [driverName])
-
File "C:\Python27\lib\site-packages\pyttsx\drivers\sapi5.py", line 19, in <module>
-
import win32com.client
-
ImportError: No module named win32com.client
First, it's not spelling the complete number that the user provided. For e.g.: I entered 20300 & it said "twenty thousand,", that's it. It didn't say the proper "Twenty thousand, three hundred".
Second, when i entered -20300, it returned "not a 5-digit number". I know that this has something to do with .isdigit method that i used, i don't know what to do about it so that negative numbers can also be considered as proper inputs.
Third, i have tried to make it say the complete spelling of numbers by using Espeak & pyttsx both but it keeps returning errors. I tried this: - import subprocess
-
text = int(str(spellnum(num)))
-
subprocess.call('espeak '+text, shell=True)
-
Output was: - Please enter your 5 digit number:35345
-
Your number is: thirty five thousand,
-
-
Traceback (most recent call last):
-
File "C:\Python27\prj.py", line 48, in <module>
-
text = int(str(spellnum(num)))
-
ValueError: invalid literal for int() with base 10: ' thirty five thousand,'
-
Please know that i'm new to Python. Any kind of help is appreciated.
3 2056 zmbd 5,501
Expert Mod 4TB
Did you ever get this sorted?
Yes, i worked out the problem & got my project to work.
zmbd 5,501
Expert Mod 4TB
That's great,
If you have a moment, would you mind posting how you solved your quandary? Doing so might help the next poor lost soul... :)
thnx
-z
Sign in to post your reply or Sign up for a free account.
Similar topics
by: antonovaCCCS |
last post by:
In our old VB 6 application we utilize a mail merge feature of Word 97 with
MS Access. A table in Access is populated from VB and a Word template is
wired to that table. So all we do in the code is...
|
by: Ken Varn |
last post by:
I have a managed C++ function that accepts an IntPtr argument. I am passing
in a variable of type HANDLE for the IntPtr argument. The compiler does not
issue any warnings for this, so I am...
|
by: Pavils Jurjans |
last post by:
Hello,
I am somewhat lost in the implicit/expicit possible/impossible type casting
in C#...
I need to write a class, which among other things, must have wat to read a
numeric value type, and...
|
by: msinghindia |
last post by:
I am creating an application which need to convert document files into
XML. Then read the xml files for specific words in specific format. I
am using Microsoft.Office.Interop for converting the...
|
by: XHengDF |
last post by:
I am a new gay to use the library boost, so i confused by some
details!
now, anybody could help me to explain the difference between
boost::bind and boost::lambda::bind when i use the library. I...
|
by: coder_lol |
last post by:
MS VS 7.0 happily resolves by SmartPointer and Inheritance, but I got
to use another target compiler and it does not accept user conversion
for templates. Can I forced a recast somehow? I have...
|
by: vidhyapriya |
last post by:
hi all,
is there any DLL file to convert pdf to word using asp.net or vb.net
|
by: doll |
last post by:
hi
i want to convert a number in the numerical form to words..please help me.. i want to know the design(form design) also..so please provide me the code and the design in vb.net
thanking you
|
by: 1230987za |
last post by:
Hi,
I have the following 2 C files:
f.c:
#include <stdio.h>
void banana_peel(char c, short s, float f){
printf("char c = %c short s = %d float f = %f \n", c, s, f);
}
|
by: KYG |
last post by:
Hi ,
I'm trying to design and build a web app (my first C++ app) using the
WT C++ web toolkit. Been looking for a way to read an MS Word doc into
a 'stream?' and manipulate (search, copy/ delete...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
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...
|
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...
|
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,...
|
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,...
|
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...
|
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...
| |