Problems with special character (c...)

Asked

Viewed 105 times

0

I’m making a system with Speech Recognition where as I speak it goes saving in a file . db (or .txt) but I noticed that the following characters appear when I speak a word with special characters like ç:

Would anyone know the reason for this and how to resolve it? I have tried to find it in several places but found nothing in relation to it

Follows as it print on terminal and as saved on doc:

inserir a descrição da imagem aqui

That’s the part of the code:

with SR.Microphone() as source:
        winsound.Beep(1500, 250) # Recording
        audio = r.listen(source)
        winsound.Beep(500, 250)   # End
        with open(nm_song, 'wb') as song:
              song.write(audio.get_wav_data())
  try:
        fala = r.recognize_google(audio, language="pt-BR")
        print('Você disse: ' + r.recognize_google(audio, language="pt-BR"))
        with open('C:\\Users\\User\\Desktop\\Bots\\Klo\\yk12mmkiy78.txt', 'a') as f:
              f.write(fala + ';')
  except SR.UnknownValueError:
        _naoEntendi("Eu não entendi, poderia ser mais claro por favor?")
  • 1

    put the part of the code in which it saves in the file.

  • @Wictorchaves I edited with the code

  • 1

    I believe your file has another character formatting. Try using the encoding="utf-8" to force accept the special characters in front of the 'a' to see if the problem persists.

  • 2

    @Murilochaves thank you very much, solved the problem!

  • @Erickvieira have, formalized the answer below, if you want to validate it as useful. Thank you.

1 answer

1


Is causing character incompatibility between what you are typing and the file you want to create.

Try to use the encoding="utf-8" at the time of addition of the information in txt.

with SR.Microphone() as source:
        winsound.Beep(1500, 250) # Recording
        audio = r.listen(source)
        winsound.Beep(500, 250)   # End
        with open(nm_song, 'wb') as song:
              song.write(audio.get_wav_data())
  try:
        fala = r.recognize_google(audio, language="pt-BR")
        print('Você disse: ' + r.recognize_google(audio, language="pt-BR"))
        with open('C:\\Users\\User\\Desktop\\Bots\\Klo\\yk12mmkiy78.txt', 'a', encoding="utf-8") as f:
              f.write(fala + ';')
  except SR.UnknownValueError:
        _naoEntendi("Eu não entendi, poderia ser mais claro por favor?")
  • 1

    Sorry it took me so long to respond, it worked out, thank you very much!

  • Tranquil @Erickvieira, I’m glad it all worked out.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.