Giter VIP home page Giter VIP logo

audio_player's Introduction

前言

用于做为独立的音频播放器使用。
支持HTTP API,可以配合其他程序协同工作。

使用&部署

开发系统:win11
python:3.10
安装依赖:pip install -r requirements.txt
其他依赖:ffmpeg
运行:python app.py
浏览器访问:http://127.0.0.1:5600/index.html

整合包

github:https://github.com/Ikaros-521/audio_player/releases
迅雷云盘: https://pan.xunlei.com/s/VNitDF0Y3l-qwTpE0A5Rh4DaA1
夸克网盘: https://pan.quark.cn/s/936dcae8aba0

API

添加音频数据到播放列表

使用 POST 请求到以下 URL:

http://127.0.0.1:5600/play

请求体(json字符串):

      
{
  "voice_path": "out\\2.mp3",
  "content": "音频文本内容",
  "random_speed": {
      "enable": false,
      "max": 1.3,
      "min": 0.8
  },
  "speed": 1,
  "insert_index": 0
}
      
  

参数说明:

  • voice_path: 音频文件路径
  • content: 音频文本内容
  • random_speed enable: 启用随机播放功能(非必填,不填默认读取本地配置)
  • random_speed max: 随机播放的最大速度(非必填,不填默认读取本地配置)
  • random_speed min: 随机播放的最小速度(非必填,不填默认读取本地配置)
  • speed: 播放速度(非必填,不填默认读取本地配置)
  • insert_index: 数据插入列表的索引值(非必填,不填默认末尾插入)

返回数据:

      
// 成功返回
{"code": 200, "message": "添加音频信息成功!"}
    
  
    
// 失败返回
{"code": -1, "message": "添加音频信息失败!{e}"}
      
  

暂停播放

使用 GET 请求到以下 URL:

http://127.0.0.1:5600/pause_stream

恢复播放

使用 GET 请求到以下 URL:

http://127.0.0.1:5600/resume_stream

跳过当前播放

使用 GET 请求到以下 URL:

http://127.0.0.1:5600/skip_current_stream

清空播放列表

使用 GET 请求到以下 URL:

http://127.0.0.1:5600/clear

获取播放列表

使用 GET 请求到以下 URL:

http://127.0.0.1:5600/get_list

配置

      
{
  "device_index": 5,
  "captions_printer": {
    "api_ip_port": "http://127.0.0.1:5500",
    "enable": false
  },
  "random_speed": {
    "enable": false,
    "max": 1.3,
    "min": 0.8
  },
  "speed": 1,
  "random_audio_interval": {
    "enable": false,
    "max": 3,
    "min": 0.1
  },
  "audio_interval": 0.5,
  "priority_mapping": {
    "copywriting": 1, 
    "abnormal_alarm": 1, 
    "trends_copywriting": 10, 
    "idle_time_task": 10,
    "image_recognition_schedule": 10,
    "local_qa_audio": 20,
    "comment": 20,
    "song": 20,
    "read_comment": 20,
    "gift": 20,
    "follow": 20,
    "reread": 30,
    "direct_reply": 30
  },
  "ai_vtuber": {
    "api_ip": "127.0.0.1",
    "api_port": 8082,
    "callback_enable": false
  }
}
      
  

配置说明:

  • device_index: 声卡设备索引值
  • random_speed enable: 启用随机播放功能
  • random_speed max: 随机播放的最大速度
  • random_speed min: 随机播放的最小速度
  • speed: 播放速度
  • captions_printer enable: 启用对接web字幕打印机
  • captions_printer api_ip_port: web字幕打印机服务的API地址
  • random_audio_interval enable: 启用随机音频间隔功能
  • random_audio_interval max: 随机音频播放的最大间隔
  • random_audio_interval min: 随机音频播放的最小间隔
  • audio_interval: 音频播放间隔
  • priority_mapping: 音频数据优先级(type键值,值越大优先级越高)
  • ai_vtuber enable: 启用ai_vtuber回传功能
  • ai_vtuber api_ip: ai_vtuber内部http服务ip
  • ai_vtuber api_port: ai_vtuber内部http服务端口

FAQ

1.5600端口冲突
可以修改app.pyjs/index.js中,搜索5600,全部改成你的新端口即可。

更新日志

  • 2024-04-29

    • 新增 AI Vtuber回传功能,配合闲时任务的待播放音频数 功能
  • 2024-03-20

    • 配置文件新增优先级配置项,针对各个音频数据类型,可以自定义优先级进行排队,用于实现弹幕优先于文案的这种效果。
  • 2024-02-18

    • 更换协议为GPL3.0
  • 2024-01-21

    • 修复传参不携带type键时的插入异常bug
  • 2024-01-16

    • 支持传入随机速度等参数来控制输出音频效果
    • 新增实时刷新的当前播放列表显示框
    • 添加音频新增 插入索引字段,可以自定义插入的位置,用于让音频可以插队(默认非文案的音频自动插到文案前面)
    • 新增配置项 随机音频间隔和音频间隔,用于控制音频播放的间隔,让机器嘴歇会
  • 2024-01-15

    • 修改列表为列表的形式,提高了数据可操作性
    • 增加了线程锁保护
    • 修改暂停、恢复播放功能实现,实现真正意义上的暂停和暂停点恢复播放。
  • 2023-11-02

    • 给播放线程追加异常捕获,起码不会直接挂了
    • 新增web字幕打印机的对接
    • 美化UI
  • 2023-11-01

    • 新增跳过当前播放、清空播放列表和获取播放列表功能
    • 优化文档
  • 2023-10-31

    • 优化UI排版
    • 新增暂停/恢复播放功能
    • 补充API文档
  • 2023-10-29

    • 基本功能通过,可以本地调用播放音频
    • 删除频率配置,新增播放速度、随机播放开关和上下限配置
  • 2023-10-28

    • 开发中

audio_player's People

Contributors

ikaros-521 avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

hcoder1949 ly827

audio_player's Issues

出现如下错误后,不能继续播放音频

2023-11-06 16:01:45,743 - D:\GitHub_pro\audio_player\utils\audio_play_center.py[line:117] - INFO: 添加音频数据={'voice_path': 'song/ikaros/枝垂樱.mp3', 'content': 'song/ikaros/枝垂樱.mp3'}
2023-11-06 16:01:45,743 - D:\GitHub_pro\audio_player\app.py[line:162] - INFO: 添加音频信息成功!
2023-11-06 16:01:45,746 - D:\GitHub_pro\audio_player\utils\audio_play_center.py[line:86] - ERROR: Traceback (most recent call last):
  File "src\\gevent\\_semaphore.py", line 249, in gevent._gevent_c_semaphore.Semaphore.acquire
  File "src\\gevent\\_abstract_linkable.py", line 521, in gevent._gevent_c_abstract_linkable.AbstractLinkable._wait
  File "src\\gevent\\_abstract_linkable.py", line 487, in gevent._gevent_c_abstract_linkable.AbstractLinkable._wait_core
  File "src\\gevent\\_abstract_linkable.py", line 490, in gevent._gevent_c_abstract_linkable.AbstractLinkable._wait_core
  File "src\\gevent\\_abstract_linkable.py", line 442, in gevent._gevent_c_abstract_linkable.AbstractLinkable._AbstractLinkable__wait_to_be_notified
  File "src\\gevent\\_abstract_linkable.py", line 451, in gevent._gevent_c_abstract_linkable.AbstractLinkable._switch_to_hub
  File "src\\gevent\\_greenlet_primitives.py", line 61, in gevent._gevent_c_greenlet_primitives.SwitchOutGreenletWithLoop.switch
  File "src\\gevent\\_greenlet_primitives.py", line 65, in gevent._gevent_c_greenlet_primitives.SwitchOutGreenletWithLoop.switch
  File "src\\gevent\\_gevent_c_greenlet_primitives.pxd", line 35, in gevent._gevent_c_greenlet_primitives._greenlet_switch
gevent.exceptions.LoopExit: This operation would block forever
	Hub: <Hub '' at 0x2032f8e0e00 backend=default ptr=<cdata 'struct uv_loop_s *' 0x000002032FAC0030> pending=0 ref=0 callbacks=0 thread_ident=0x11f4>
	Handles:
[HandleState(handle=<cdata 'struct uv_handle_s *' 0x000002032E635BB8>, type=b'check', watcher=<gevent.libuv.loop.loop at 0x2032fa93400 backend=default ptr=<cdata 'struct uv_loop_s *' 0x000002032FAC0030> pending=0 ref=0 callbacks=0>, ref=0, active=1, closing=0),
 HandleState(handle=<cdata 'struct uv_handle_s *' 0x000002032E677958>, type=b'timer', watcher=<gevent.libuv.loop.loop at 0x2032fa93400 backend=default ptr=<cdata 'struct uv_loop_s *' 0x000002032FAC0030> pending=0 ref=0 callbacks=0>, ref=0, active=1, closing=0),
 HandleState(handle=<cdata 'struct uv_handle_s *' 0x000002032E636D98>, type=b'prepare', watcher=<gevent.libuv.loop.loop at 0x2032fa93400 backend=default ptr=<cdata 'struct uv_loop_s *' 0x000002032FAC0030> pending=0 ref=0 callbacks=0>, ref=0, active=1, closing=0),
 HandleState(handle=<cdata 'struct uv_handle_s *' 0x000002032E636AD8>, type=b'check', watcher=<gevent.libuv.loop.loop at 0x2032fa93400 backend=default ptr=<cdata 'struct uv_loop_s *' 0x000002032FAC0030> pending=0 ref=0 callbacks=0>, ref=1, active=0, closing=0),
 HandleState(handle=<cdata 'struct uv_handle_s *' 0x000002032E744C88>, type=b'async', watcher=<async_ at 0x2032fa91cf0 callback=<function AbstractLoop._init_loop_and_aux_watchers.<locals>.<lambda> at 0x000002032F9E6950> args=() watcher=<cdata 'struct uv_async_s *' owning 224 bytes> handle=<cdata 'void *' 0x000002032FAC7EC0> ref=False>, ref=0, active=1, closing=0)]

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:\GitHub_pro\audio_player\utils\audio_play_center.py", line 46, in play_audio
    data_json = self.audio_json_queue.get(block=True)
  File "D:\Miniconda\envs\ai_vtb\lib\queue.py", line 171, in get
    self.not_empty.wait()
  File "D:\Miniconda\envs\ai_vtb\lib\threading.py", line 320, in wait
    waiter.acquire()
  File "D:\Miniconda\envs\ai_vtb\lib\site-packages\gevent\thread.py", line 112, in acquire
    acquired = BoundedSemaphore.acquire(self, blocking, timeout)
  File "src\\gevent\\_semaphore.py", line 180, in gevent._gevent_c_semaphore.Semaphore.acquire
  File "src\\gevent\\_semaphore.py", line 260, in gevent._gevent_c_semaphore.Semaphore.acquire
  File "src\\gevent\\_semaphore.py", line 348, in gevent._gevent_c_semaphore.Semaphore._Semaphore__acquire_from_other_thread
  File "src\\gevent\\_semaphore.py", line 390, in gevent._gevent_c_semaphore.Semaphore._Semaphore__acquire_using_two_hubs
  File "src\\gevent\\_abstract_linkable.py", line 427, in gevent._gevent_c_abstract_linkable.AbstractLinkable._quiet_unlink_all
  File "src\\gevent\\_abstract_linkable.py", line 150, in gevent._gevent_c_abstract_linkable.AbstractLinkable.unlink
  File "src\\gevent\\_abstract_linkable.py", line 150, in gevent._gevent_c_abstract_linkable.AbstractLinkable.unlink
  File "src\\gevent\\_abstract_linkable.py", line 157, in gevent._gevent_c_abstract_linkable.AbstractLinkable.unlink
AttributeError: 'int' object has no attribute 'pending'

2023-11-06 16:01:45,749 - D:\GitHub_pro\audio_player\utils\audio_play_center.py[line:86] - ERROR: Traceback (most recent call last):
  File "D:\GitHub_pro\audio_player\utils\audio_play_center.py", line 48, in play_audio
    audio = AudioSegment.from_file(voice_path)
  File "D:\Miniconda\envs\ai_vtb\lib\site-packages\pydub\audio_segment.py", line 651, in from_file
    file, close_file = _fd_or_path_or_tempfile(file, 'rb', tempfile=False)
  File "D:\Miniconda\envs\ai_vtb\lib\site-packages\pydub\utils.py", line 60, in _fd_or_path_or_tempfile
    fd = open(fd, mode=mode)
FileNotFoundError: [Errno 2] No such file or directory: 'song/ikaros/枝垂樱.mp3'

OSError: [Errno -9998] Invalid number of channels

2023-11-05 15:44:32,202 - D:\GitHub_pro\audio_player\pkg\audio_player\utils\audio_play_center.py[line:86] - ERROR: Traceback (most recent call last):
File "D:\GitHub_pro\audio_player\pkg\audio_player\utils\audio_play_center.py", line 65, in play_audio
self.stream = self.audio.open(format=self.audio.get_format_from_width(wf.getsampwidth()),
File "D:\GitHub_pro\audio_player\pkg\audio_player\Miniconda3\lib\site-packages\pyaudio_init_.py", line 639, in open
stream = PyAudio.Stream(self, *args, **kwargs)
File "D:\GitHub_pro\audio_player\pkg\audio_player\Miniconda3\lib\site-packages\pyaudio_init_.py", line 441, in init
self._stream = pa.open(**arguments)
OSError: [Errno -9998] Invalid number of channels

BUG & 建议

2023/11/14更新
1.aduio_player在后台运行时,web字幕打印机会在上一首音乐播放完毕,即将播放下一首音乐的时候,在直播间中显示音频播放路径,是否能够把这个地方进行优化完善,让其不再显示音频播放路径?
此处功能完善有益于避免在直播间中,输出不必要的文本内容,便于观众的观赏。

2.目前aduio_player的循环播放功能依赖LOOP脚本工具进行实现,能否将其整合到aduio_playeri当中通过webui的界面选项来实现循环播放的功能?
此处功能完善有益于小白进行操作,降低循环播放功能的使用门槛,通过此整合可以让aduio_player的音频播放功能更加完善。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.