How to make a Python script to audio read a text file on phone ?

dey.sumit.kr at gmail.com dey.sumit.kr at gmail.com
Sun Mar 17 17:48:31 EDT 2013


On Sunday, March 17, 2013 7:34:18 PM UTC+5:30, Nic wrote:
> I've installed Python on my Nokia E71 (Symbian S60 3rd FP1) and found a script example which can read out text, see example below.
> 
>  I want to make the script to asks me for a text file instead and then reads out the content. I guess it works with a .txt file, dont know if other formats work.  Regards!
> 
> 
> 
> 
> 
> [Quote]
> 
> 
> 
> # Copyright (c) 2006 Jurgen Scheible
> 
> # This script performs a query with a single-field dialog (text input field)
> 
> # and lets the phone speak out the text (text to speech) that the users have typed in
> 
> # NOTE: this script runs only with Python S60 version 3.1.14 or above
> 
> # NOTE: this script doesn't work on all S60 phones neccessarily. Check your phone model if it has text to speech capability at all
> 
> 
> 
> import appuifw
> 
> import audio
> 
> 
> 
> text = appuifw.query(u"Type a word:", "text")
> 
> audio.say(text)
> 
> 
> 
> [End Quote]

Here is a code that works fine for PC. Hope it'll work for you..

def op():
    global TXT, L
    filepath = tkFileDialog.askopenfilename(filetypes=[("Text Files","*.txt")])
    if(len(filepath) == 0):
        return 0
    F = open(filepath,'r')
    TXT = F.read()
    F.close()
    filename = filepath.split("/")
    filename = filename[-1]
    L.config(text=filename+": "+filepath)

def play():
    global TXT
    audio.say(TXT) ##Used as mentioned
    print "said"
    

from Tkinter import *
import Tkconstants, tkFileDialog

import audio ##used as mentioned

TXT = ""

root = Tk()
root.title("Read that Out!!")

L = Label(text="No File Selected!",width="35",fg="black",bg="white")
L.grid(row=1,column=1)

F = Frame(root)
F.grid(row=2,column=1)

Button(F,text="Open File",command=op).grid(row=1,column=1)
Button(F,text="Read File",command=play).grid(row=1,column=2)

root.mainloop()



More information about the Python-list mailing list