포스트

[ChatGPT 사용 일기] ChatGPT한테 한글을 영문 표기법으로 바꾸는 코드 만들어달라고 하기 C#, 재밌는 tts 듣기


간혹 한글 키보드를 사용할 수 없을 때 영어 알파벳으로만 한국어를 표기해보려고 한 적 있으실텐데요, 어디에 회원가입하려 할 때에는 '철수'는 'cheolsu', 'chulsu' 처럼 쓰기도 합니다.

이렇게 바꾸는 과정을 'Romanize 한다'고 합니다.

그래서 저는 Chatgpt에게 유니티C#으로 romanize 코드를 작성해달라고 요청해보았습니다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using System;
using System.Text;
using System.Globalization;

class KoreanRomanizer
{
    public static string Romanize(string koreanText)
    {
        StringBuilder romanizedText = new StringBuilder();
        TextElementEnumerator enumerator = StringInfo.GetTextElementEnumerator(koreanText);

        while (enumerator.MoveNext())
        {
            string element = enumerator.GetTextElement();
            if (IsHangul(element))
            {
                romanizedText.Append(RomanizeHangul(element));
            }
            else
            {
                romanizedText.Append(element);
            }
        }

        return romanizedText.ToString();
    }

    private static bool IsHangul(string text)
    {
        foreach (char c in text)
        {
            if (c  0xD7A3)
                return false;
        }
        return true;
    }

    private static string RomanizeHangul(string hangul)
    {
        int code = hangul[0] - 0xAC00;
        int jongseong = code % 28;
        int jungseong = ((code - jongseong) / 28) % 21;
        int choseong = (((code - jongseong) / 28) - jungseong) / 21;

        string romanizedChoseong = ChoseongToRoman(choseong);
        string romanizedJungseong = JungseongToRoman(jungseong);
        string romanizedJongseong = JongseongToRoman(jongseong);

        return romanizedChoseong + romanizedJungseong + romanizedJongseong;
    }

    private static string ChoseongToRoman(int choseong)
    {
        string[] choseongRomanized =
        {
            "g", "kk", "n", "d", "tt", "r", "m", "b", "pp", "s",
            "ss", "", "j", "jj", "ch", "k", "t", "p", "h"
        };
        return choseongRomanized[choseong];
    }

    private static string JungseongToRoman(int jungseong)
    {
        string[] jungseongRomanized =
        {
            "a", "ae", "ya", "yae", "eo", "e", "yeo", "ye", "o", "wa",
            "wae", "oe", "yo", "u", "wo", "we", "wi", "yu", "eu", "ui", "i"
        };
        return jungseongRomanized[jungseong];
    }

    private static string JongseongToRoman(int jongseong)
    {
        string[] jongseongRomanized =
        {
            "", "k", "kk", "ks", "n", "nj", "nh", "d", "l", "lg", "lm", "lb", "ls", "lt", "lp", "lh",
            "m", "b", "bs", "s", "ss", "ng", "j", "c", "k", "t", "p", "h"
        };
        return jongseongRomanized[jongseong];
    }
}

1
2
3
4
5
6
7
8
9
public class Romanizer : MonoBehaviour
{
    void Start()
    {
        string input = "나는 철수라고 했다고 해. 너는 누구니?";
        string romanized = KoreanRomanizer.Romanize(input);
        Debug.Log(romanized);
    }
}

object에 붙여서 작동시켜보니 잘 되네요!

원래는 다음과 같이 다소 복잡해보이는 파이썬 코드를 참조하려고 했었는데요, https://github.com/YiHoze/texwrapper/blob/master/hanroman.py

https://github.com/YiHoze/texwrapper/blob/master/hanroman.py {“payload”:{“allShortcutsEnabled”:false,”fileTree”:{“”:{“items”:[{“name”:”_epub”,”path”:”_epub”,”contentType”:”directory”},{“name”:”_html”,”path”:”_html”,”contentType”:”directory”},{“name”:”images”,”path”:”images”,”contentType”:”directory”},{“name”:”.gitignore”,”path”:”.gitignore”,”contentType”:”fil…

여러 패키지 모듈을 가져다 쓰는 부분을 구현할 수가 없어서 chatgpt로 새로 작성했습니다.


chatgpt 정말 유용하네요! chatgpt 네 이놈.

https://youtu.be/vh08JS96g6Y

[영상]

(이러한 로마표기를 tts가 읽는 음성은 이전 피그마 설명 글에서 같이 올렸었어요.ㅎㅎ)

https://blog.naver.com/devramyun/223195168623

[20230828] 피그마와 피그잼(FigJam) 근래에 피그마로 앱 UI 프로토타입을 디자인하면서 그 편리함에 많이 감탄하고 있는데요, 이번에는 좀더 … 근래에 피그마로 앱 UI 프로토타입을 디자인하면서 그 편리함에 많이 감탄하고 있는데요, 이번에는 좀더 …

https://youtu.be/MIXdDZxeVaw

[영상]

sticker

감사합니다.

sticker

이 기사는 저작권자의 CC BY 4.0 라이센스를 따릅니다.