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如何使用Array和ArrayList做同样的事情?   用户界面使Java JScrollpane仅垂直滚动   查找字符串中最长的重复子字符串所需的算法Java函数?   java我想在listview中检索firebase数据   java如何使用Jsoup提取链接?   java 安卓。看法使用RTEditor时发生充气异常   maven为什么自动依赖是错误版本?(java.lang.ClassNotFoundException:org.junit.jupiter.api.MethodOrderContext)   使用apachespark进行java开发   java glDrawBuffers是否应该翻转IntBuffer?   java在添加回调之前完成CompletableFuture<T>   用Java构建搜索树   java将web应用程序部署到Heroku   active directory Java LDAP:属性为只读   启动Spring启动应用程序时未考虑java DB端口   使用Mockito的java模拟   C++从运行时运行java的过程。执行出口代码139   javascript使用脚本删除旧SonarQube项目   java代理每节点模型?   java无法在Android上通过Internet从PC服务器接收UDP数据   在bluemix:java上加载p12时发生ibm云错误。木卫一。IOException:数据不足