diff --git a/Languages/Pronunciation/pronunciation.ipynb b/Languages/Pronunciation/pronunciation.ipynb new file mode 100644 index 00000000..8dd449d8 --- /dev/null +++ b/Languages/Pronunciation/pronunciation.ipynb @@ -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", + "\"Open" + ] + }, + { + "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 +}