-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A notebook for listening to pronunciation in other languages (#206)
* Create pronunciation.ipynb * Version update
- Loading branch information
Showing
1 changed file
with
124 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"![Callysto.ca Banner](https://github.com/callysto/curriculum-notebooks/blob/master/callysto-notebook-banner-top.jpg?raw=true)\n", | ||
"\n", | ||
"<a href=\"https://hub.callysto.ca/jupyter/hub/user-redirect/git-pull?repo=https%3A%2F%2Fgithub.com%2Fcallysto%2Fcurriculum-notebooks&branch=master&subPath=Languages/Pronunciation/pronunciation.ipynb&depth=1\" target=\"_parent\"><img src=\"https://raw.githubusercontent.com/callysto/curriculum-notebooks/master/open-in-callysto-button.svg?sanitize=true\" width=\"123\" height=\"24\" alt=\"Open in Callysto\"/></a>" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Language Pronunciation\n", | ||
"\n", | ||
"As we are learning to speach additional languages, we need to listen to how words and phrases are pronounced. We will use the [Google Translate](https://pypi.org/project/googletrans) and [Google Text-to-Speech](https://pypi.org/project/gTTS) code libraries for this.\n", | ||
"\n", | ||
"In the cell below, you can change what the `translate_this` variable is equal to, for example `translate_this = 'goodbye'`, then click the `►Run` button to display and speak the translation." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"translate_this = 'Hello, how are you today?'\n", | ||
"source = 'en'\n", | ||
"destination = 'fr'\n", | ||
"\n", | ||
"from googletrans import Translator\n", | ||
"translator = Translator()\n", | ||
"result = translator.translate(translate_this, src=source, dest=destination)\n", | ||
"print(translate_this)\n", | ||
"print(result.text)\n", | ||
"import gtts\n", | ||
"gtts.gTTS(result.text, lang=destination, slow=True).save('pronunciation.wav')\n", | ||
"import IPython.display as ipd\n", | ||
"ipd.display(ipd.Audio('pronunciation.wav'))" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Available Languages\n", | ||
"\n", | ||
"To list the languages that are available for translation, `►Run` the following code cell." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"gtts.lang.tts_langs()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Speaking a Word or Phrase\n", | ||
"\n", | ||
"If we have a word or phrase that has already been translated, we can use the following code cell to listen to its pronunciation.\n", | ||
"\n", | ||
"To speed up the speaking, change `slow=True` to `slow=False`." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"speak_this = 'Dar la vuelta a la tortilla'\n", | ||
"language = 'es'\n", | ||
"\n", | ||
"gtts.gTTS(speak_this, lang=language, slow=True).save('pronunciation.wav')\n", | ||
"ipd.display(ipd.Audio('pronunciation.wav'))" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Conclusion\n", | ||
"\n", | ||
"When learning languages it is important to listen to pronunciation. In this notebook we used code libraries to produce machine-generated audio files so we could hear what words and phrases sound like." | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"[![Callysto.ca License](https://github.com/callysto/curriculum-notebooks/blob/master/callysto-notebook-banner-bottom.jpg?raw=true)](https://github.com/callysto/curriculum-notebooks/blob/master/LICENSE.md)" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.8.3" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 4 | ||
} |