|
@@ -1,129 +0,0 @@
|
|
|
-{
|
|
|
- "cells": [
|
|
|
- {
|
|
|
- "cell_type": "code",
|
|
|
- "execution_count": null,
|
|
|
- "id": "initial_id",
|
|
|
- "metadata": {
|
|
|
- "collapsed": true
|
|
|
- },
|
|
|
- "outputs": [],
|
|
|
- "source": [
|
|
|
- "from pathlib import Path\n",
|
|
|
- "from aiortc import MediaStreamTrack\n",
|
|
|
- "from aiortc.contrib.media import MediaRecorder, MediaPlayer\n",
|
|
|
- "\n",
|
|
|
- "from aiortc.mediastreams import AudioStreamTrack\n",
|
|
|
- "\n",
|
|
|
- "from hubsbot import Bot\n",
|
|
|
- "from hubsbot.peer import Peer\n",
|
|
|
- "from hubsbot.consumer import ConsumerFactory as BaseConsumerFactory, TextConsumer as BaseTextConsumer, VoiceConsumer, Message\n",
|
|
|
- "from hubsbot.consumer.aiortc import RecorderFactory\n",
|
|
|
- "\n",
|
|
|
- "import logging\n",
|
|
|
- "logging.getLogger().setLevel(logging.DEBUG)"
|
|
|
- ]
|
|
|
- },
|
|
|
- {
|
|
|
- "cell_type": "code",
|
|
|
- "execution_count": null,
|
|
|
- "outputs": [],
|
|
|
- "source": [
|
|
|
- "class TextConsumer(BaseTextConsumer):\n",
|
|
|
- " def __init__(self, peer: Peer):\n",
|
|
|
- " self.peer = peer\n",
|
|
|
- "\n",
|
|
|
- " async def on_message(self, msg: Message):\n",
|
|
|
- " print(f'Message from {self.peer.id}: {msg}')\n",
|
|
|
- "\n",
|
|
|
- "class ConsumerFactory(RecorderFactory):\n",
|
|
|
- " def create_text_consumer(self, peer: Peer) -> TextConsumer:\n",
|
|
|
- " return TextConsumer(peer)"
|
|
|
- ],
|
|
|
- "metadata": {
|
|
|
- "collapsed": false
|
|
|
- },
|
|
|
- "id": "4ca06ddc04e96118"
|
|
|
- },
|
|
|
- {
|
|
|
- "cell_type": "code",
|
|
|
- "execution_count": null,
|
|
|
- "outputs": [],
|
|
|
- "source": [
|
|
|
- "\n",
|
|
|
- "bot = Bot(\n",
|
|
|
- " host='9de36d10e9.us2.myhubs.net',\n",
|
|
|
- " room_id='NUCedZ2',\n",
|
|
|
- " avatar_id=\"basebot\",\n",
|
|
|
- " display_name=\"Python User\",\n",
|
|
|
- " consumer_factory=ConsumerFactory(Path('/home/andrew/Projects/MEPhI/HubsBot/audio-sample/output')),\n",
|
|
|
- " # voice_track=AudioStreamTrack()\n",
|
|
|
- " voice_track=MediaPlayer('/home/andrew/Projects/MEPhI/HubsBot/audio-sample/03. The Art Of War.mp3').audio\n",
|
|
|
- ")"
|
|
|
- ],
|
|
|
- "metadata": {
|
|
|
- "collapsed": false
|
|
|
- },
|
|
|
- "id": "3ee170157087975e"
|
|
|
- },
|
|
|
- {
|
|
|
- "cell_type": "code",
|
|
|
- "execution_count": null,
|
|
|
- "outputs": [],
|
|
|
- "source": [
|
|
|
- "import asyncio\n",
|
|
|
- "import nest_asyncio\n",
|
|
|
- "\n",
|
|
|
- "nest_asyncio.apply()\n",
|
|
|
- "asyncio.get_event_loop().run_until_complete(bot.join())"
|
|
|
- ],
|
|
|
- "metadata": {
|
|
|
- "collapsed": false
|
|
|
- },
|
|
|
- "id": "f1db38b3356b571d"
|
|
|
- },
|
|
|
- {
|
|
|
- "cell_type": "code",
|
|
|
- "execution_count": null,
|
|
|
- "outputs": [],
|
|
|
- "source": [
|
|
|
- "asyncio.get_event_loop().run_until_complete(bot.close())"
|
|
|
- ],
|
|
|
- "metadata": {
|
|
|
- "collapsed": false
|
|
|
- },
|
|
|
- "id": "53fa6a2f12621806"
|
|
|
- },
|
|
|
- {
|
|
|
- "cell_type": "code",
|
|
|
- "execution_count": null,
|
|
|
- "outputs": [],
|
|
|
- "source": [],
|
|
|
- "metadata": {
|
|
|
- "collapsed": false
|
|
|
- },
|
|
|
- "id": "11080b4b3383d31a"
|
|
|
- }
|
|
|
- ],
|
|
|
- "metadata": {
|
|
|
- "kernelspec": {
|
|
|
- "name": "hubsbot",
|
|
|
- "language": "python",
|
|
|
- "display_name": "HubsBot"
|
|
|
- },
|
|
|
- "language_info": {
|
|
|
- "codemirror_mode": {
|
|
|
- "name": "ipython",
|
|
|
- "version": 2
|
|
|
- },
|
|
|
- "file_extension": ".py",
|
|
|
- "mimetype": "text/x-python",
|
|
|
- "name": "python",
|
|
|
- "nbconvert_exporter": "python",
|
|
|
- "pygments_lexer": "ipython2",
|
|
|
- "version": "2.7.6"
|
|
|
- }
|
|
|
- },
|
|
|
- "nbformat": 4,
|
|
|
- "nbformat_minor": 5
|
|
|
-}
|