Python中播放音乐伴奏 并且新年祝福

Python中播放音乐伴奏,可以使用多种方法和库来实现。不同的库支持不同类型的音乐文件。以下是一些常见的库及其支持的音乐文件类型:

在Python中播放音乐伴奏,可以使用多种方法和库来实现。不同的库支持不同类型的音乐文件。以下是一些常见的库及其支持的音乐文件类型:

def print_3d_heart():
    print("新年快乐")
    for angle in range(0, 360, 10):  # 旋转360度,每次旋转10度
        os.system('cls' if os.name == 'nt' else 'clear')  # 清屏
        for row in range(15):
            for col in range(15):
                x = col - 7.5
                y = row - 7.5
                # 3D旋转效果
                x_rot = x * (1 + 0.1 * (angle / 180))
                y_rot = y * (1 - 0.1 * (angle / 180))
                if ((x_rot ** 2 + y_rot ** 2 - 25) ** 3 - x_rot ** 2 * y_rot ** 3 <= 0):
                    print("\033[91m*\033[0m", end=" ")
                else:
                    print(" ", end=" ")
            print()
        time.sleep(0.1)  # 每次旋转后暂停0.1秒
 

1. winsound模块(Windows)

  • 支持的文件类型:主要支持WAV格式的音频文件。

  • 示例代码

    Python复制

    import winsound
    winsound.PlaySound("path_to_your_sound.wav", winsound.SND_FILENAME)

2. simpleaudio模块(跨平台)

  • 支持的文件类型:支持WAV格式的音频文件。

  • 安装方法

    sh复制

    pip install simpleaudio
  • 示例代码

    Python复制

    import simpleaudio as sa
    wave_obj = sa.WaveObject.from_wave_file("path_to_your_sound.wav")
    play_obj = wave_obj.play()
    play_obj.wait_done()

3. pygame模块(跨平台)

  • 支持的文件类型:支持多种格式,包括WAV、MP3、OGG等。

  • 安装方法

    sh复制

    pip install pygame
  • 示例代码

    Python复制

    import pygame
    pygame.mixer.init()
    pygame.mixer.music.load("path_to_your_sound.mp3")
    pygame.mixer.music.play()
    while pygame.mixer.music.get_busy():
        pygame.time.Clock().tick(10)

4. pydub模块(跨平台)

  • 支持的文件类型:支持多种格式,包括WAV、MP3、OGG等。

  • 安装方法

    sh复制

    pip install pydub
  • 示例代码

    Python复制

    from pydub import AudioSegment
    from pydub.playback import play
    sound = AudioSegment.from_file("path_to_your_sound.mp3")
    play(sound)

5. vlc模块(跨平台)

  • 支持的文件类型:支持多种格式,包括WAV、MP3、OGG、AVI、MP4等。

ReadMe Release Version beta_1.0 index.py imageMatlab.py This is more or less a wrapper for Matplotlib imaging functions such that their behavior is equivalent, in terms of colormap, aspect and so forth, to the expected behavior of Matlab's functions. sepVocal.py This script can be used to execute the desired separation. See below for an example of use of this file. SIMM.py This script implements the actual algorithm for parameter estimation. It is mainly used by sepVocal.py. tracking.py The Viterbi decoding algorithm is implemented in this script. Requirements: These scripts have been tested with Python 2.7, The packages that are required to run the scripts are pydub,ffmepg, Numpy, Spicy, Matplotlib. One can respectively find the latest versions at the following addresses: http://pydub.com/ https://ffmpeg.org http://numpy.org/ http://scipy.org/ http://matplotlib.sourceforge.net/ Notes: Prefer recent versions of the above packages, in order to avoid compatibility issues, notably for Matplotlib. Note that this latter package is not necessary for the program to run, although you might want to watch a bit what is happening! Spicy should be version 0.8+, since we use its io.wavefile module to read the wave files. We once used the audio lab module, but it would seem that it is a bit more complicated to install (with the benefit that many more file formats are allowed). Usage: The easy way to use these scripts is to run the exec package of our release version: http://www.github.com/beata_1.0 for more develop: you can run the index.py on pycharm directly. note: the output files will create under you source wav file. ContactMe Email:xlzhang14@fudan.edu.cn
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

交通上的硅基思维

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值