Skip to content

Instantly share code, notes, and snippets.

@evildmp
Forked from Chive/hamlet.py
Last active January 3, 2016 12:47
Show Gist options
  • Save evildmp/b114ae9fa0e998958e6f to your computer and use it in GitHub Desktop.
Save evildmp/b114ae9fa0e998958e6f to your computer and use it in GitHub Desktop.
Hamlet, for two voices (after Ulises Carrión)
# 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
response = requests.get('http://shakespeare.mit.edu/hamlet/full.html')
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:
subprocess.call(['say', '-v', 'daniel', '-r', '20', name])
else:
subprocess.call(['say', '-v', 'kate', '-r', '20', name])
except KeyboardInterrupt:
exit('aborted')
requests
beautifulsoup4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment