美文网首页unity
[Unity 3d] LyricParser(歌词转换器) -

[Unity 3d] LyricParser(歌词转换器) -

作者: 雨落随风 | 来源:发表于2019-06-26 21:38 被阅读8次

    Unity 中解析歌词的解决方案。

    GitHub 上的工程多如繁星,有些好的仓库,但凡不经意间错过了就很难找回,故稍作采撷,希望能帮助到有心人。
    本文集以一个小的功能点为单位行文,也便于拾取罢!

    简介:

    笔者今天推荐的仓库叫 LyricParser。 - 歌词转换
    它演示了如何将常见的歌词文件解析并同步显示出来。

    功能:

    1. 解析歌词文件..
    2. 歌词同步

    使用:

        protected Lyric mLyric = new Lyric();
        void Start () {
            string lyricPath = GetTestLyricPath();
            mLyric.Load(lyricPath);
    
            mAudioSource.Play();
        }
        
        // Update is called once per frame
        void Update () {
            // update show lyric
            UpdateLyric();
        }
    
        protected void UpdateLyric() // 更新歌词显示
        {
            // test code
            // get current music play timestamp
            Int64 timestamp = GetCurrentTimestamp();
            // search current lyric
            LyricItem currentItem = mLyric.SearchCurrentItem(timestamp);
         
                // show lyrics from index (currentItem.mIndex - showLyricSize) to (currentItem.mIndex + showLyricSize)
                List<LyricItem> items = mLyric.GetItems();
                int showLyricSize = 3;
                foreach (LyricItem item in items)
                {
                    if (item == currentItem)
                    {
                        // 如果播放的是当前这一句,高亮它
                        text += Lyric.WrapStringWithColorTag(item.mText, 255, 0, 0) + System.Environment.NewLine; 
                    }
                    else if ((null == currentItem && item.mIndex < showLyricSize) 
                        || (null != currentItem && item.mIndex >= currentItem.mIndex - showLyricSize 
                        && item.mIndex <= currentItem.mIndex + showLyricSize))
                    {
                        //继续拼接其余部分
                        text += item.mText + System.Environment.NewLine; 
                    }
                }
          
        }
    

    演示:

    LyricParser
    • 为了让画面活泼一点,笔者特意加了个土味特效,哈哈!


      LyricParser+UniWinApi+UnityAudioVisualization
    • 使用Unity简单的做了个桌面播放器,频谱 + 歌词+全透,只有又深又浅的背景才能显得出效果,散了散了~

    链接:

    egg53231323/LyricParser: An music lyric display demo. Implement with c# and unity.

    结语:

    你正在想的也许是别人已经做过了的,Unity做播放器 显示歌词,想想还是挺有意思的!

    本文集持续更新ing,喜欢记得点赞关注哦!

    相关文章

      网友评论

        本文标题:[Unity 3d] LyricParser(歌词转换器) -

        本文链接:https://www.haomeiwen.com/subject/xmbhcctx.html