-
-
Save evildmp/b114ae9fa0e998958e6f to your computer and use it in GitHub Desktop.
Hamlet, for two voices (after Ulises Carrión)
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
# 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') |
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
requests | |
beautifulsoup4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment