Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
reading text file with gtts
#1
i am looking to retrieve contents that are in a file i am able to print the contents that i search but i am not able to use gtts to speak it.

def record_audio():
    r = sr.Recognizer()
    with sr.Microphone() as source:
        r.adjust_for_ambient_noise(source)
        print('listening:')
        r.pause_threshold = .7
        r.energy_threshold = 4000
        r.dynamic_energy_adjustment_damping = True
        audio = r.listen(source)
    data = ''  # the audio that is said
    try:
        data = r.recognize_google(audio)
        print('you said: ' + data)  # 'you said' + the data that was said
    except sr.UnknownValueError:
        print('google speech recognition could not understand the audio, unknown error')
    except sr.RequestError as e:
        print('request results from google speech recognition service error' + e)
    except LookupError:  # speech is unintelligible
        print("Could not understand audio")
    return data


def assistant_response(text):
    print(text)
    tts = gTTS(text=text, lang="en-US", slow=False, )
    filename = "voice.mp3"
    tts.save(filename)
    playsound(filename, True)
    os.remove(filename)

"""==============================================================================================================="""

"""File location information"""
read_appointment_file_location = r"My_appointments"
write_appointment_file_location = r"My_appointments"
is_file_appointment_empty_location = r"My_appointments"




class Cal:
    def __init__(self, date, time, appointment):
        self.date = date
        self.time = time
        self.appointment = appointment


    def __str__(self):
        return "Date: {0}\n Time: {1}\n Appointment: {2}".format(self.date, self.time, self.appointment)

    def date(self):
        return_date = self.date
        return return_date


def search_appointment():

    # search_name=input("Enter the name\n")
    appointment_book_file = open(read_appointment_file_location, mode="rb")
    search_date = get_date()
    is_appointment_found = False
    list_appointment = pickle.load(appointment_book_file)
    for each_appointment in list_appointment:
        appointment_date = each_appointment.date
        search_date = search_date.lower()
        appointment_date = appointment_date.lower()
        if appointment_date == search_date:
            print(each_appointment)
            assistant_response(each_appointment)
            is_appointment_found = True

    if not is_appointment_found:
        print("No appointment found with the provided search date")

    return


def suffix(d):
    return 'th' if 11 <= d <= 13 else {1: 'st', 2: 'nd',3:'rd'}.get(d % 10, 'th')


def custom_strftime(format, t):
    return t.strftime(format).replace('{S}', str(t.day) + suffix(t.day))


def get_date():
    my_date = datetime.datetime.today()
    return custom_strftime('%B {S} %Y', datetime.datetime.now())
   # return calendar.day_name[my_date.weekday()] + " " + custom_strftime('%B {S}, %Y', datetime.datetime.now())

search_appointment()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Sad problems with reading csv file. MassiJames 3 559 Nov-16-2023, 03:41 PM
Last Post: snippsat
  Reading a file name fron a folder on my desktop Fiona 4 851 Aug-23-2023, 11:11 AM
Last Post: Axel_Erfurt
  Reading data from excel file –> process it >>then write to another excel output file Jennifer_Jone 0 1,046 Mar-14-2023, 07:59 PM
Last Post: Jennifer_Jone
  Reading a file JonWayn 3 1,057 Dec-30-2022, 10:18 AM
Last Post: ibreeden
Thumbs Up Need to compare the Excel file name with a directory text file. veeran1991 1 1,062 Dec-15-2022, 04:32 PM
Last Post: Larz60+
  Reading Specific Rows In a CSV File finndude 3 940 Dec-13-2022, 03:19 PM
Last Post: finndude
  Excel file reading problem max70990 1 865 Dec-11-2022, 07:00 PM
Last Post: deanhystad
  Replace columns indexes reading a XSLX file Larry1888 2 951 Nov-18-2022, 10:16 PM
Last Post: Pedroski55
  Failing reading a file and cannot exit it... tester_V 8 1,754 Aug-19-2022, 10:27 PM
Last Post: tester_V
  Reading .csv file doug2019 4 1,659 Apr-29-2022, 09:55 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020