midi.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:jose 作者: lnmds 项目源码 文件源码
def midi(self, ctx: commands.Context,
                   tempo: int=120, *, data: str=None):
        """
        Convert text to MIDI. Multiple channels can be used by splitting text with |.
        Letters are converted to their pitch values using a mapping.

        Full documentation about it is not provided, read the code at
        https://github.com/lnmds/jose/blob/master/ext/midi.py

        To give longer input than a discord message allows you may upload a .txt file of up to 20 KiB.
        """
        if data is None:
            try:
                data = await self.download_data(ctx.message)
            except Exception as err:
                log.exception('error downloading file at midi')
                raise self.SayException('We had an error while downloading '
                                        'the file, are you sure it is text?')

        before = time.monotonic()
        midi_file = await self.make_midi(tempo, data)
        duration = (time.monotonic() - before) * 1000

        if midi_file is None:
            return await ctx.send('Failed to generate a MIDI file!')

        file = io.BytesIO()
        await self.loop.run_in_executor(None, midi_file.writeFile, file)
        file.seek(0)

        wrapped = discord.File(file, filename='boop.midi')
        await ctx.send(f'Took {duration:.3f}ms!', file=wrapped)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号