当前位置: 首页 > article >正文

python源码:指定麦克风/音响播放歌曲

前言

        我使用pygame实现了指定麦克风/音响播放歌曲的功能,主要目的是解决直播过程的多源声道控制问题。

 

代码 

# 查看自己的音频设备
# 请记住目标音频设备的具体名称
import pygame as mixer
import pygame._sdl2 as sdl2

mixer.init() # Initialize the mixer, this will allow the next command to work
print(sdl2.audio.get_audio_device_names(False)) # set to False to return playback(output) devices, set to True to return record(input) devices.
mixer.quit() # Quit the mixer as it's initialized on your main playback device
from pygame import mixer
import time

# 使用设备:Voicemeeter In 1 (VB-Audio Voicemeeter VAIO)
# 来负责播放
mixer.init(devicename = 'Voicemeeter In 1 (VB-Audio Voicemeeter VAIO)')
# 播放本地歌曲
mixer.music.load("Reol.MP3") # Load the mp3

# 播放接口流式歌曲
# from io import BytesIO
# response = requests.get('http://xxxxxx/wav2wav1')
# audio_data = BytesIO(response.content)
# mixer.music.load(audio_data)

mixer.music.play() # Play it

# 监测音频是否播放完毕
while mixer.music.get_busy():  # wait for music to finish playing
    time.sleep(1)

http://www.kler.cn/a/349455.html

相关文章:

  • [spring]spring事务和事务传播机制
  • 第二届 龙信杯 电子数据取证竞赛部分Writeup
  • 哈佛混不下去的学者,32年后拿下诺奖:发现miRNA
  • 【宽搜】5.leetcode 199 二叉树的右视图
  • steam上传游戏问题汇总
  • 使用console.time进行性能分析
  • 2.4.ReactOS系统运行级别IRQL的切换
  • Python案例 | 测试网络的下载速度上传速度和 ping 延迟
  • 春意盎然:Spring Boot课程答疑系统
  • Redis的应用以及Redis工具类的封装
  • Vue2项目中使用 echarts(5.2.2)图表组件含代码(二)
  • 【旋转数组】二分法专题
  • HDLBits中文版,标准参考答案 | 3.3 Building Larger Circuits | 构建更大的电路
  • 本地生活全域抽佣系统--本地生活服务商的便捷运营平台
  • 使用C++写一个自己定义的图像格式,写入磁盘
  • unity学习-灯光类型
  • 高可用之限流 08-leaky bucket漏桶算法
  • leetcode解题思路分析(一百六十一)1394 - 1400 题
  • ros service不走是为什么
  • STM32的独立看门狗定时器(IWDG)技术介绍