ive made a mistake https://www.twitch.tv/videos/351127119
Last active
December 19, 2018 03:42
-
-
Save codl/be2a4f1d86671b4c1226dae5eac98b67 to your computer and use it in GitHub Desktop.
a nightmare
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[aws] | |
access_key_id=poopy | |
secret_access_key=pee poo | |
[mastodon] | |
api_base_url=https://mastodon.social/ | |
client_id=hjkfdlshk | |
client_secret=hfjdsklfhjdskl | |
access_token=hfdjskl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subprocess | |
import boto3 | |
import mastodon | |
import configparser | |
import random | |
from tempfile import TemporaryFile | |
from bs4 import BeautifulSoup | |
import html | |
conf = configparser.ConfigParser() | |
conf.read('config.cfg') | |
polly = boto3.client('polly', | |
aws_access_key_id=conf['aws']['access_key_id'], | |
aws_secret_access_key=conf['aws']['secret_access_key']) | |
mas = mastodon.Mastodon( | |
client_id = conf['mastodon']['client_id'], | |
client_secret = conf['mastodon']['client_secret'], | |
access_token = conf['mastodon']['access_token'], | |
api_base_url = conf['mastodon']['api_base_url']) | |
def speak(text:str): | |
VOICES = ('Amy', 'Emma', 'Brian') | |
resp = polly.synthesize_speech( | |
Text=text, | |
VoiceId=random.choice(VOICES), | |
LexiconNames=['codl'], | |
OutputFormat='ogg_vorbis', | |
TextType='text' | |
) | |
body = resp['AudioStream'] | |
temp = TemporaryFile() | |
temp.write(body.read()) | |
temp.seek(0) | |
proc = subprocess.Popen(('ffplay', '-nodisp', '-autoexit', '-'), stdin=temp, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) | |
class Listener(mastodon.StreamListener): | |
def on_update(self,status): | |
soup = BeautifulSoup(status.content, 'html.parser') | |
text = " ".join(soup.strings) | |
if status.spoiler_text.strip(): | |
text = "Content Warning: " + status.spoiler_text | |
text = html.unescape(text) | |
speak(text) | |
print('@{}: {}'.format(status.account.username, text)) | |
mas.stream_public(Listener()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mastodon.py | |
boto3 | |
beautifulsoup4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment