Skip to content

Commit

Permalink
Adding google narrator & button
Browse files Browse the repository at this point in the history
J0K3Rn committed Aug 26, 2023
1 parent 33fa4c2 commit 32a5316
Showing 6 changed files with 27 additions and 5 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,34 @@
# Chinese-Flash-Cards

Educational app to assist in learning Chinese (Mandarin). Flash cards to memorize 1000 of the most everyday used words. Includes Chinese->English translations and pinyin. Created using Tkinter.
Educational app to assist in learning Chinese (Mandarin). Flash cards to memorize 1000 of the most everyday used words. Includes Chinese->English translations and pinyin and narrator. Created using Tkinter.

Features:
- Flashcards of over 1000 of the most commonly used Chinese words
- Chinese Pinyin, narrator, and the English translation for each card
- Mark works 'known' `` or 'unknown' `x`
- Cards marked as known will not be shown again in the stack
- Click the card to flip it and see translation
- Click the card to flip it and see the translation
- Extra csv files will be generated in the data directory after you run for more review

Chinese words taken from: https://github.com/hermitdave/FrequencyWords/tree/master/content/2018/zh_cn

TODO:
- Hookup ChatGPT to generate Chinese sentences
- google translate -> https://pypi.org/project/googletrans/
- google translate narrator -> https://pypi.org/project/google-speech/
- hook up Google translate to do automatic translations (for each character and sentence) -> https://codelabs.developers.google.com/codelabs/cloud-translation-python3#0
- Create another flash card stack by web scraping https://studychinese101.com/1000-chinese-sentences-in-daily-life.html
- Look into implementing list from HSK -> https://en.wiktionary.org/wiki/Appendix:HSK_list_of_Mandarin_words

External Packages Used:
- Chinese Pinyin: https://pypi.org/project/pinyin/
- Google Translate Narrator: https://pypi.org/project/google-speech/

How to run:
- Python 3.11.4 is highly recommended to resolve tkinter issues
- Download repository
- Open downloaded repository with a command line interface
- run `pip install pandas pinyin`
- run `pip install pandas pinyin google-speech sox`
- make sure you have sox installed! For MacOS terminal: `brew install sox`. This is used to run google-speech
- run `python main.py`
- App window will open
- Click the card to see the translation, and once again to see original card
Binary file added images/volume_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 21 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
@@ -2,6 +2,8 @@
from random import choice
import pandas as pd
import pinyin
from google_speech import Speech
import sox
#import re

BACKGROUND_COLOR = "#B1DDC6"
@@ -50,20 +52,24 @@ def __init__(self):
self.card_word = self.canvas.create_text(400, 263, fill="#000000", font=("Ariel", 60, "bold"))
self.card_pinyin_label = self.canvas.create_text(400, 363, fill="#000000", font=("Ariel", 60, "bold"))
self.canvas.itemconfig(self.card_pinyin_label, state='hidden')
self.show_pinyin_button = tk.Button(window, highlightbackground="#FFFFFF", bg="#FFFFFF", text="Show Pinyin", command=self.show_pinyin) # , height=3, width=10)
self.canvas.bind("<Button-1>", self.on_click)

# Buttons
self.correct_img = tk.PhotoImage(file="images/right.png")
self.incorrect_img = tk.PhotoImage(file="images/wrong.png")
self.volume_img = tk.PhotoImage(file="images/volume_icon.png")
self.volume_img = self.volume_img.subsample(10)
self.wrong_button = tk.Button(highlightbackground=BACKGROUND_COLOR, bg=BACKGROUND_COLOR, image=self.incorrect_img, command=self.incorrect)
self.correct_button = tk.Button(highlightbackground=BACKGROUND_COLOR, bg=BACKGROUND_COLOR, image=self.correct_img, command=self.correct)
self.show_pinyin_button = tk.Button(window, highlightbackground="#FFFFFF", bg="#FFFFFF", text="Show Pinyin", command=self.show_pinyin) # , height=3, width=10)
self.narrator_button = tk.Button(window, highlightbackground="#FFFFFF", bg="#FFFFFF", image=self.volume_img, command=self.narrate)

# Grid Layout
self.canvas.grid(column=0, row=0, columnspan=15, rowspan=10)
self.wrong_button.grid(column=5, row=10)
self.correct_button.grid(column=9, row=10)
self.show_pinyin_button.grid(column=7, row=7)
self.narrator_button.grid(column=7, row=8)

# Set up flashcards
self.next_card()
@@ -75,6 +81,20 @@ def show_pinyin(self):
# self.show_pinyin_button.destroy()
self.canvas.itemconfig(self.card_pinyin_label, state='normal')

def narrate(self):
global side
global current_card
lang = ''
text = ''
if side == 'front':
lang = "zh"
text = current_card["Chinese"]
elif side == 'back':
lang = "en"
text = current_card["English"]
speech = Speech(text, lang)
speech.play()

def flip_card(self):
global side
global current_card
Binary file modified screenshots/card_back.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screenshots/card_front_no_pinyin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screenshots/card_front_with_pinyin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 32a5316

Please sign in to comment.