首先创建一个MidiFile对象 创建一个(或多个)MidiTrack对象,并将其append到MidiFile中 向一个(或多个)MidiTrack对象内添加Message对象(包括program_change、note_on、note_off等)和MetaMessage对象(用以表示MIDI文件的节拍、速度、调式等属性) 保存MidiFile对象 下面我通过对Message和MetaMessage这两个十分重要的概念的...
play_note(1, 0.25, track, channel=1) # 的 if num == 2: play_note(1, 0.5, track, channel=1) # (妈) play_note(6, 0.5, track, channel=1) # 地(一) play_note(5, 0.5, track, channel=1) play_note(5, 3, track, channel=1) # 方(样) play_note(3, 0.5, track) # 海(走...
MIDI file saved at: 'output\test\vocals.mid' 转换好的钢琴旋律midi文件存放在output目录下,直接双击播放即可,也可以通过代码进行播放: ''' pg_midi_sound101.py play midi music files (also mp3 files) using pygame tested with Python273/331 and pygame192 by vegaseat ''' import pygame as pg def ...
Python可以通过一些库来读取和播放MIDI文件。 Python MIDI库 Python有多个库可以处理MIDI文件,其中mido是一个常用的库。mido库提供了创建、读取和修改MIDI文件的功能。 import mido from mido import MidiFile 读取MIDI文件 mid = MidiFile('example.mid') 播放MIDI文件 for msg in mid.play(): print(msg) 这种...
播放MIDI文件 for msg in mid.play(): outport.send(msg) 上述代码中,MidiFile用于读取MIDI文件,mido.open_output()打开默认的MIDI输出端口,然后通过循环将MIDI消息发送到输出端口以播放音乐。 Pygame.midi库 pygame是一个用于编写多媒体应用程序的库,pygame.midi模块可以用来播放MIDI文件。首先需要安装pygame库: ...
首先创建一个MidiFile对象 创建一个(或多个)MidiTrack对象,并将其append到MidiFile中 向一个(或多个)MidiTrack对象内添加Message对象(包括program_change、note_on、note_off等)和MetaMessage对象(用以表示MIDI文件的节拍、速度、调式等属性) 保存MidiFile对象 ...
with MidiFile(f1) as mid: for msg in mid: print(msg) 运行python mido_msg.py happy_birthday.mid 编写play_mid.py 如下 # -*- coding: utf-8 -*- import os import sys import time from tkinter import filedialog import traceback import pygame ...
# conda install -c cogsci pygame import pygame def play_music(midi_filename): '''Stream music_file in a blocking manner''' clock = pygame.time.Clock() pygame.mixer.music.load(midi_filename) pygame.mixer.music.play() while pygame.mixer.music.get_busy(): clock.tick(30) # check if pl...
本文实例讲述了python使用PyGame播放Midi和Mp3文件的方法。分享给大家供大家参考。具体实现方法如下: ''' pg_midi_sound101.py play midi music files (also mp3 files) using pygame tested with Python273/331 and pygame192 by vegaseat ''' import pygame as pg def play_music(music_file): ''' stream...
play midi music files (also mp3 files) using pygame tested with Python273/331 and pygame192 by vegaseat ''' import pygame as pg def play_music(music_file): ''' stream music with mixer.music module in blocking manner this will stream the sound from disk while playing ...