Twitch网站的界面,可以与他们的视频和聊天进行交互

python-twitch-stream的Python项目详细描述


https://readthedocs.org/projects/python-twitch-stream/badge/https://travis-ci.org/317070/python-twitch-stream.svghttps://coveralls.io/repos/317070/python-twitch-stream/badge.svghttps://img.shields.io/badge/license-MIT-green.svg

python抽搐流

python twitch stream是一个简单的轻量级库,您可以使用它 将您的python视频发送到twitch并实时与聊天作出反应。 它的主要功能是:

  • 支持以线程安全的方式向您的抽搐发送音频和视频 频道。
  • 允许通过发送聊天信息与频道的聊天进行交互 以及阅读其他用户发布的内容。

安装

简而言之,您可以安装已知的兼容版本的ffmpeg和 最新的稳定版本超过了pip。

pip install python-twitch-stream

请确保同时安装最新的ffmpeg版本:

sudo add-apt-repository ppa:mc3man/trusty-media
sudo apt-get update && sudo apt-get install ffmpeg

ffmpeg库需要非常新(编写于2015年10月)。 当 使用旧版本的ffmpeg或avconv运行流,包括 不限于6GB内存使用,音频和 音频和视频的同步。

或者,安装最新的 python Twitch流开发版本通过:

pip install git+https://github.com/317070/python-twitch-stream

文件

在线提供文档:http://python-twitch-stream.readthedocs.org/

要获得支持,请使用the repository上的github问题。

示例

这是一个小例子,它创建了一个Twitch流 根据中提供的颜色更改视频的颜色 聊天。

from__future__importprint_functionfromtwitchstream.outputvideoimportTwitchBufferedOutputStreamfromtwitchstream.chatimportTwitchChatStreamimportargparseimporttimeimportnumpyasnpif__name__=="__main__":parser=argparse.ArgumentParser(description=__doc__)required=parser.add_argument_group('required arguments')required.add_argument('-u','--username',help='twitch username',required=True)required.add_argument('-o','--oauth',help='twitch oauth ''(visit https://twitchapps.com/tmi/ ''to create one for your account)',required=True)required.add_argument('-s','--streamkey',help='twitch streamkey',required=True)args=parser.parse_args()# load two streams:# * one stream to send the video# * one stream to interact with the chatwithTwitchBufferedOutputStream(twitch_stream_key=args.streamkey,width=640,height=480,fps=30.,enable_audio=True,verbose=False)asvideostream, \
        TwitchChatStream(username=args.username.lower(),# Must provide a lowercase username.oauth=args.oauth,verbose=False)aschatstream:# Send a chat message to let everybody know you've arrivedchatstream.send_chat_message("Taking requests!")frame=np.zeros((480,640,3))frequency=100last_phase=0# The main loop to create videoswhileTrue:# Every loop, call to receive messages.# This is important, when it is not called,# Twitch will automatically log you out.# This call is non-blocking.received=chatstream.twitch_receive_messages()# process all the messagesifreceived:forchat_messageinreceived:print("Got a message '%s' from %s"%(chat_message['message'],chat_message['username']))ifchat_message['message']=="red":frame[:,:,:]=np.array([1,0,0])[None,None,:]elifchat_message['message']=="green":frame[:,:,:]=np.array([0,1,0])[None,None,:]elifchat_message['message']=="blue":frame[:,:,:]=np.array([0,0,1])[None,None,:]elifchat_message['message'].isdigit():frequency=int(chat_message['message'])# If there are not enough video frames left,# add some more.ifvideostream.get_video_frame_buffer_state()<30:videostream.send_video_frame(frame)# If there are not enough audio fragments left,# add some more, but take care to stay in sync with# the video! Audio and video buffer separately,# so they will go out of sync if the number of video# frames does not match the number of audio samples!elifvideostream.get_audio_buffer_state()<30:x=np.linspace(last_phase,last_phase+frequency*2*np.pi/videostream.fps,int(44100/videostream.fps)+1)last_phase=x[-1]audio=np.sin(x[:-1])videostream.send_audio(audio,audio)# If nothing is happening, it is okay to sleep for a while# and take some pressure of the CPU. But not too long, if# the buffers run dry, audio and video will go out of sync.else:time.sleep(.001)

有关全功能示例,请参见examples/color.py, 并检查Tutorial是否深入 同样的解释。更多示例保存在examples directory中。

发展

python twitch stream是一个正在进行的工作,但是是稳定的。随便问吧 或添加带有代码更新的拉取请求。

变更日志

1.0(2015-10-30)

第一次释放。 功能:

  • 发送抽搐流(视频和音频)
  • 阅读和发送抽搐聊天。
  • 核心贡献者,按字母顺序排列:
    • 乔纳斯退化(@317070)
  • 特别感谢

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
在Java中使用Kotlin值类   在Hadoop中表示大文本块作为键的java   java安卓工作室;布局设计视图;   字典Java确定字符串是否以映射中的键开头   JavaG1:混合gc和完全gc之间有什么区别?   java Camunda升级组织。阿帕奇。平民语言错误   java Scanner类具有NextLine无限循环   安卓 GCM Java服务器:发送带有重音字符的消息   java我正在构建一个兴趣计算应用程序,我的项目构建良好,有1个警告,但它不会在我的设备上打开   java在Tilera TileGX上构建OpenJDK 8   GUI中的java惰性初始化与急切初始化   java JodaTime四舍五入到最近的一刻钟   java如何限制菜单。SpringRoo中的jspx可以避免对其他用户的实体执行CRUD操作   java我应该将缓冲流链接到输入流,还是在将声音库作为嵌入式资源加载时使用URL类?