Skip to content

Instantly share code, notes, and snippets.

@evildmp
Last active March 12, 2016 15:42
Show Gist options
  • Save evildmp/d8aae1dc9e40e79b2b46 to your computer and use it in GitHub Desktop.
Save evildmp/d8aae1dc9e40e79b2b46 to your computer and use it in GitHub Desktop.
Poets & programmers and Python at PyCon Slovakia 2016 - resources

Many thanks to PyCon Slovakia 2016 for the invitation and to Divio for the opportunity to attend.

References

About me

  • Daniele Procida
  • Community & doumentation manager at Divio
  • developer of django CMS
  • core developer of Django Project, Django Software Foundation Board member
  • EvilDMP on IRC (#django, #django-cms etc on freenode), GitHub, Twitter etc
# coding=UTF8
# Hamlet, for two voices
# after Ulises Carrión
#
# https://en.wikipedia.org/wiki/Ulises_Carrión
#
# Ulises Carrión's recording of Hamlet, for two voices:
# https://www.dropbox.com/s/vyi3psnt0da2hu0/Hamlet%20for%20two%20voices.mp3?dl=0
# Uses the OS X "say" command.
import subprocess
import re
import requests
from bs4 import BeautifulSoup
text_source = "http://shakespeare.mit.edu/hamlet/full.html"
print("Getting %s" % text_source)
response = requests.get(text_source)
soup = BeautifulSoup(response.content, 'html.parser')
try:
for ind, tag in enumerate(soup.find_all('a', {'name': re.compile('speech.*')})):
# get first item with stripped tags
name = next(tag.stripped_strings)
# You will need to download the appropriate voices. The British English
# Daniel and Kate do quite well.
#
# You might think that Mexican Spanish voices Juan and Angelica would be
# better still, but they're not as good.
if ind % 2 == 0:
print(name)
subprocess.call(['say', '-v', 'daniel', '-r', '200', name])
else:
print(name)
subprocess.call(['say', '-v', 'kate', '-r', '200', name])
except KeyboardInterrupt:
exit('aborted')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment