0

How to convert unicode to Kruti Dev 010?

I'm using python speech recognition library to convert speech to text and displaying it using tkinter Text widget but it's not displaying in Kruti Dev.

      # class variable 
      __thisTextArea = Text(__root)
      Font_tuple = font.Font(family='Kruti Dev 010', size=16)

      # inside constructor
      self.__thisTextArea.config(font = self.Font_tuple,   yscrollcommand=self.__thisScrollBar.set)
      
      # inside speech recognition function
      self.__thisTextArea.insert(INSERT, text_obtained)
      self.__thisTextArea.insert(END,' ')

Also, on saving the file speech recognized text is not saving however typed text is saving.

KrutiDev to Unicode Converter.

tripleee
  • 175,061
  • 34
  • 275
  • 318
Naman Jain
  • 195
  • 2
  • 15
  • 2
    If the font Kruti Dev does not support Unicode, you will need to figure out which encoding it uses, and encode your text into that. – tripleee Jul 01 '21 at 06:15
  • There is a plethora of online converters so I assume the encoding is at least informally documented. – tripleee Jul 01 '21 at 06:16
  • 1
    Maybe see also https://stackoverflow.com/questions/21722660/where-do-i-set-the-character-encoding-in-a-java-swing-application-so-that-i-can – tripleee Jul 01 '21 at 06:17
  • @tripleee I found a code to convert Kruti Dev to Unicode, which seems to convert Unicode to roman characters only as pointed [by you](https://stackoverflow.com/questions/21722660/where-do-i-set-the-character-encoding-in-a-java-swing-application-so-that-i-can). But I am not able to reverse that. As mentioned in the question, it's not saving speech-recognized text. Can you help me with this? – Naman Jain Jul 01 '21 at 12:53
  • Anyone who knows Python can probably do that if you can show an unambiguous mapping between Kruti code points and their Unicode counterparts. I'm not familiar enough with devanagari script to be able to decide whether joiners etc are correct, so probably somebody who can read the script would be better equipped to whip up the code. Where did you find the conversion code? Probably [edit] the question to include a pointer. – tripleee Jul 01 '21 at 12:59
  • Isn't Unicode to Roman precisely what you want, though? I got the impression that Kruti just replaces the display glyphs of simple ASCII characters with devanagari characters (but I spent like 10 minutes this morning so I could easily be wrong). – tripleee Jul 01 '21 at 13:03
  • @tripleee [KrutiDev to Unicode Converter](https://gist.github.com/trinopoty/b83b136ff25cdfda0cbe774dc17e43ca) – Naman Jain Jul 02 '21 at 07:56
  • Unfortunately, the gist seems to be written for Python 2. I hacked up a Python 3 conversion but I can't tell if it is correct: https://gist.github.com/tripleee/e679dcbe0e18e07da40ffc04a255e747 – tripleee Jul 02 '21 at 08:48
  • It's correct. I have switched strings in replace function but it's giving an empty string. – Naman Jain Jul 02 '21 at 16:52
  • So if `self.__thisTextArea.insert(INSERT, ';gk\u00a1 is vkidk ;wfudksM')` does what you want, you could remove all the [tag:tkinter] stuff here and just focus on the question "How can I convert `'यहाँ पे आपका यूनिकोड'` to the corresponding Kruti-encoded string `';gk\u00a1 is vkidk ;wfudksM'` and similarly for other Unicode strings in devanagarii" for a proper [mre]. – tripleee Jul 02 '21 at 19:30

1 Answers1

1

I'm not familiar enough with either tkinter or devanagari to tell whether this is at all helpful, but I found another project with a pair of functions which map both ways; is this what you are looking for?

The code at https://github.com/jmcmanu2/python_practice/blob/master/Unicode%20KrutiDev%20converter.py doesn't have an explicit license, so I am not comfortable publishing it here, but I have a slightly updated version for Python 3 in a gist at https://gist.github.com/tripleee/b82a79f5b3e57dc6a487ae45077cdbd3 for the time being. (The original was almost Python 3 already so the tweaking required was minimal, though I ripped out unrelated parts which dealt with Excel files.)

With that code available as an import, does this do what you are asking?

from unicode2krutidev import Unicode_to_KrutiDev

# ...

class something:
    __thisTextArea = Text(__root)
    Font_tuple = font.Font(family='Kruti Dev 010', size=16)

    def __init__(self, ...):
      # ...
      self.__thisTextArea.config(font = self.Font_tuple,   yscrollcommand=self.__thisScrollBar.set)
      # ...

    def recognize_speech(self, ...):
      # ...
      text_converted = Unicode_to_KrutiDev(text_obtained)
      self.__thisTextArea.insert(INSERT, text_converted)
      self.__thisTextArea.insert(END,' ')
      # ...
      self.save_to_database(text_obtained)
tripleee
  • 175,061
  • 34
  • 275
  • 318