[Python] Convert number inside a string to english words

Discussão em 'Python' iniciado por Stack, Fevereiro 23, 2025.

  1. Stack

    Stack Membro Participativo

    I'm currently working on neural text to speech, and to process the data I need several steps. One step is convert the numeric in string into english character words instead of numeral. The closest thing I can found is num2words, but I'm not sure how to apply it to an existing string. Here's my use case :

    I have list of string like this

    list_string = ['I spent 140 dollar yesterday','I have 3 brothers and 2 sisters']


    I wanted to convert into :

    output_string = ['I spent one hundred forty dollar yesterday','I have three brothers and two sisters']


    The struggle is one text might consist of several number, and even if I can get the numeric using re.match, I'm not sure how to put the number back to the string.

    No need to worry about floating number or year for now since I don't have that kind of number inside my string.

    Thanks

    Continue reading...

Compartilhe esta Página