コード例 #1
0
def get_russian(sent):
    print(f'Starting translate sentence {sent}')
    russian = GoogleTranslator(target='ru').translate(sent)
    print(f'Translating is over. Translated sentence is {russian}')
    write_to_file(my_path, russian)
    return russian
コード例 #2
0
def google_translator():
    """Sample pytest fixture.

    See more at: http://doc.pytest.org/en/latest/fixture.html
    """
    return GoogleTranslator(target='en')
コード例 #3
0
from deep_translator import GoogleTranslator, PonsTranslator, LingueeTranslator

# examples using google translate

english_text = 'happy coding'
chinese_text = '這很好'

result_german = GoogleTranslator(source='english',
                                 target='german').translate(text=english_text)
result_french = GoogleTranslator(source='auto',
                                 target='french').translate(text=chinese_text)

print(
    f"original english text: {english_text} | translated text: {result_german}"
)  # result: fröhliche Codierung
print(
    f"original chinese text: {chinese_text} | translated text: {result_french}"
)  # result: C' est bon

# examples using linguee:
text = 'cute'
translated = LingueeTranslator(source='english',
                               target='german').translate(word=text)
print("Using Linguee ==> the translated text: ", translated)

# examples using pons:
text = 'good'
translated = PonsTranslator(source='english',
                            target='arabic').translate(word=text)
print("using Pons ==> the translated text: ", translated)
コード例 #4
0
 def __init__(self, group, db_handler):
     self._handler = db_handler
     self.group = group
     self._translator = GoogleTranslator(source='iw', target='en')
コード例 #5
0
# Importing the library we need
from deep_translator import GoogleTranslator

# Opening the text file that contains the kanji we want to translate in read-only mode
with open("words.txt", "r", encoding="utf8") as f:
    for word in f:
        try:
            # For this specific case we only want the first character
            token = word[:1] if len(word) != 1 else word
            # We translate token plus an empty space because the translator needs at least two letters
            print(token, " --> " , GoogleTranslator(source='auto', target='en').translate(token + " "))
        except Exception as e:
            print(e)
コード例 #6
0
ファイル: translate2.py プロジェクト: ribaslucian/rechat-web2
# example
# pip install -U deep_translator
import sys
from deep_translator import GoogleTranslator

translated = GoogleTranslator(source='pt', target='en').translate(sys.argv[1])
print(translated)
コード例 #7
0
 def get_binary(self, word, source_='ru', destination_='en'):
     from_src_to_dest = GoogleTranslator(source=source_, target=destination_)
     self.cldir('cache')
     gTTS(text=from_src_to_dest.translate(word), lang=destination_).save('cache/word.wav')
     return open('cache/word.wav', 'rb').read()
コード例 #8
0
from bs4 import BeautifulSoup
from fake_useragent import UserAgent
from deep_translator import GoogleTranslator
import requests, csv

ua = UserAgent()
translator = GoogleTranslator(source='auto', target='ru')
url = 'https://www.leathercountrybags.com/'

headers = {
  'User-Agent': ua.ie,
  'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9'
}

# Function to write csv file
def write_csv(row):
  with open('products.csv', 'a', encoding='utf-8', newline='') as csv_file:
    csv_writer = csv.writer(csv_file)
    # Write the received information to a csv file
    csv_writer.writerow(row)
    print('Writing csv file...')

# Function to check if data already exists in the csv file
def check_data(data):
  with open('products.csv', encoding='utf-8', newline='') as csv_file:
    reader = csv.reader(csv_file, delimiter=',')
    data_exists = False

    for row in reader:
      if data in row[0]:
        data_exists = True
コード例 #9
0
def parse_comment(request):
    request_body = dict(urllib.parse.parse_qsl(request.body.decode()))
    if not request_body.get("fbContent"):
        return JsonResponse({"result": []})
    selector = BeautifulSoup(request_body.get("fbContent"), "html.parser")

    comment_list = []
    comment_raws = selector.find_all("div", {"class": "ee"})
    for element in comment_raws:
        comment = dict()
        with suppress(Exception):
            name = element.select_one("div h3 a").get_text(strip=True)
            comment["name"] = name

        with suppress(Exception):
            profile_link = element.select_one("div h3 a").attrs.get("href", "")
            comment["profile_link"] = fb_link(profile_link)

        with suppress(Exception):
            comment_text = element.select_one("div h3 + div").get_text(strip=True)
            comment["comment_text"] = comment_text

        try:
            comment_text_eng = GoogleTranslator(source="auto", target="en").translate(
                comment.get("comment_text", "")
            )
        except Exception:
            comment_text_eng = ""
        comment["comment_text_eng"] = comment_text_eng

        with suppress(Exception):
            comment_img = element.select_one("div h3 + div + div img").attrs.get(
                "src", ""
            )
            comment["comment_img"] = comment_img

        with suppress(Exception):
            comment_time = element.select_one("abbr").get_text(strip=True)
            comment["comment_date"] = dateparser.parse(comment_time).strftime(
                "%d/%m/%Y"
            )

        with suppress(Exception):
            child_node = element.findChildren("div")
            if len(child_node) == 7:
                comment["has_reply"] = True
            else:
                comment["has_reply"] = False

        if comment.get("has_reply", False):
            with suppress(Exception):
                reply_link = element.find_all("a")[-1].attrs.get("href")
                comment["reply_link"] = "https://mbasic.facebook.com" + reply_link

        if (
            comment.get("name")
            and comment.get("profile_link")
            and comment.get("comment_date")
        ):
            comment_list.append(comment)

    return JsonResponse({"result": comment_list})
コード例 #10
0
 def __init__(self, chats: List[Chat]) -> None:
     super().__init__(chats)
     self.translator = GoogleTranslator(target='en')
コード例 #11
0
import streamlit as st
from transformers import pipeline
def summary(text):
    summarizer = pipeline("summarization")
    summary = summarizer(text[:1024], max_length=120, min_length=30, do_sample=False)
    return summary[0]['summary_text']
st.title('Text Summarisation by Yulei')
text = st.text_area('Please type the texts you want to summarise here.')
if not text:
    st.stop()

st.header('Please see your summarisation below:')
st.write(summary(text))

from deep_translator import GoogleTranslator
translated = GoogleTranslator(source='auto', target='zh-cn').translate(summary(text))
st.write(translated)
コード例 #12
0
import json
from deep_translator import GoogleTranslator # pip install -U deep_translator
translator = GoogleTranslator(source='nl', target='en')

f = open("json.json", "r")
all =f.read()
data = json.loads(all)

def translate(x, key): #replace with whatever you want your mapper to do
	if key == "caption":
		print("translating: " + x)
		return translator.translate(x)
	else:
		return x

def walk(node, key):
	if type(node) is dict:
		return {k: walk(v, k) for k, v in node.items()} #dict		
	elif type(node) is list:
		return [walk(x, key) for x in node] #list
	else:
		return translate(node, key) #leaf
		
	
new = walk(data, None)

open("translated.json", "w").write(json.dumps(new))
コード例 #13
0
def googletrans(word):
    translater = GoogleTranslator(source="en", target="es")
    word_trans = translater.translate(word)
    print(word_trans)
    return word_trans
コード例 #14
0
file = open("source.txt", "r")
lines = file.readlines()
file.close()

newText = ''
for line in lines:
    if line[0] == '*':
        print(line.rstrip())
    else:
        word_to_define = line.rstrip()
        newText += word_to_define + ' - '
        #print(word_to_define)
        dest_text = ''
        try:
            dest_text = GoogleTranslator(source='en',
                                         target='tr').translate(word_to_define)
        except:
            pass
        #dest_text = translate(line, 'tr', 'en')
        myTimer = .5
        while dest_text == '':
            time.sleep(myTimer)
            try:
                dest_text = GoogleTranslator(
                    source='en', target='tr').translate(word_to_define)
            except:
                pass
            myTimer = myTimer + myTimer
            if myTimer > 40:
                break
        #print(dest_text)
コード例 #15
0
def get_russian(my_text):
    russian = GoogleTranslator(target='ru').translate(my_text)
    return russian
コード例 #16
0
#add GEN_nr to adalasportaldata based on keylist
for x in adlasportal:
    for y in keylist:
        if x['UMCGNR'] == y['umcg_numr']:
            x['GEN_numr'] = y['GEN_numr']

#make new headers for update
for d in adlasportal:
    d['clinical_identifier'] = d['GEN_numr'] + '_' + d['ADVIESVRAAGNUMMER']
    d['belongs_to_person'] = d.pop('GEN_numr')
    d['application_date'] = (d['ADVIESVRAAG_DATUM']).replace(" 00:00", "")
    d['genetic_testcode'] = d.pop(
        'TESTCODE'
    )  #<<niet alle codes aanwezig<als 1 testcode per aanvraag dan deze oplossing
    d['testcode_decription'] = GoogleTranslator(
        source='auto', target='en').translate(d['TESTOMSCHRIJVING'])
    d['outcome'] = GoogleTranslator(source='auto',
                                    target='en').translate(d['EINDUITSLAG'])
    d['outcome_text'] = GoogleTranslator(source='auto', target='en').translate(
        d['EINDUITSLAGTEKST'])
    d['outcome_date'] = (d['EINDUITSLAG_DATUM']).replace(" 00:00", "")
    d['date_last_updated'] = datetime.now().strftime("%Y-%m-%dT%H:%M:%SZ")

#change date format
for d in adlasportal:
    d['application_date'] = datetime.strptime((d['application_date']),
                                              "%d/%m/%Y").strftime("%Y-%m-%d")
    d['outcome_date'] = datetime.strptime((d['outcome_date']),
                                          "%d/%m/%Y").strftime("%Y-%m-%d")

#'molecular_diagnosis_gene' : samengesteld met alle GA_GEN voor 1 adviesID en UMCG d.get('GA_GEN')
コード例 #17
0
def get_english(my_text):
    english = GoogleTranslator(target='en').translate(my_text)
    return english
コード例 #18
0
ファイル: main.py プロジェクト: Brenw10/speaker-to-text
def get_text_translated(text):
    try:
        return GoogleTranslator(source='auto', target='pt').translate(text)
    except:
        return
コード例 #19
0
    if name == "posix":
        os.system("gio open audioConverted.mp3")
    elif name in ("ce", "nt", "dos"):
        os.system("start audioConverted.mp3")


#texto que se ingresa por consola
text = input("Insert text for convert to audio: ")
language = input("Insert the language of translator: ")

#Traducir documentos
#language = 'es'
#pathTexto = os.getcwd()
#textTranslator = GoogleTranslator(source='en', target=language).translate_file(f'{pathTexto}/textIngles.txt')

#Traduce el texto ingresado
textTranslator = GoogleTranslator(source='auto',
                                  target=str(language)).translate(text)

#Se puede definir en text el texto que se va a leer
#lang se puede definir el lenguaje del audio lo mas usado es
#es = español y en = english
tts = gTTS(text=textTranslator, lang=language)

#Ruta donde se guarda del audio
tts.save("audioConverted.mp3")

#OPCIONAL: sirve para abrir el archivo
#si no desea abrirlo puede comentar la linea
autoOpenOperativo()
コード例 #20
0
        x['disease'] = x['problem'][0]
        x['problem_start_date'] = datetime.strptime(
            (x['problem'][1]), "%d-%m-%Y").strftime("%Y-%m-%d")
        x['problem_end_date'] = datetime.strptime(
            (x['problem'][2]), "%d-%m-%Y").strftime("%Y-%m-%d")
#changing dateformats
for x in unique_adlas:
    if 'diagnosis_date' in x:
        if "T" in x['diagnosis_date']:
            x['diagnosis_date'] = (x['diagnosis_date']).replace("T00:00", "")
        else:
            x['diagnosis_date'] = datetime.strptime(
                (x['diagnosis_date']), "%m/%d/%Y").strftime("%Y-%m-%d")
    if 'application_date' in x:
        x['application_date'] = (x['application_date']).replace("T00:00", "")
    if 'outcome_date' in x:
        x['outcome_date'] = (x['outcome_date']).replace("T00:00", "")
#adding translations
for x in unique_adlas:
    if 'testcode_decription' in x:
        x['testcode_decription'] = GoogleTranslator(
            source='auto', target='en').translate(x['testcode_decription'])
    if 'outcome_text' in x:
        x['outcome_text'] = GoogleTranslator(
            source='auto', target='en').translate(x['outcome_text'])
#pprint.pprint(unique_adlas)
#import all to clinicalevent
for i in range(0, len(unique_adlas), 1000):
    session.add_all(arguments["entityType8"], unique_adlas[i:i + 1000])
print("Total of geneticlines clinicalEvents:", len(unique_adlas))
コード例 #21
0
def execute():
    toTranslate = pyperclip.paste()
    translated = GoogleTranslator(source='auto', target='pl').translate(toTranslate)
    current.clear()
    translateGui = Gui(toTranslate, translated)
    translateGui.root.mainloop()
コード例 #22
0
from deep_translator import GoogleTranslator
import json

file = open("lang_en_ch1.json").read()
data = json.loads(file)

for key, value in data.items():
    print(f"KEY: {key}, VALUE: {value}")
    try:
        translated = GoogleTranslator(source='auto',
                                      target="pt").translate(value)
        print("Valores Traduzidos.")

        data[key] = translated

        with open("lang_en_ch1.json", "w") as outfile:
            json.dump(data, outfile, indent=4)
            outfile.close()

        print("Valor aplicado")

    except Exception as e:
        print(e)
        continue
コード例 #23
0
while bool:
    while time.time() - start <= x:
        with sr.Microphone() as source:
            print("Talk")
            # audio_text = recognizer.record(source, duration=3)
            audio_text = recognizer.listen(source)
            try:
                st = recognizer.recognize_google(audio_text)
                array = st.split()
                for i in range(len(array)):
                    if array[i] in d.keys():
                        array[i] = d[array[i]]
                s = " ".join(array)
                print(type(s))
            except Exception as e:
                print("Error: " + str(e))

            print("Time over, thanks")

            try:
                translated = GoogleTranslator(source='auto',
                                              target=dest_lang).translate(s)
                print(translated)
                mydoc.add_paragraph(translated)
                mydoc.save(file_name)
                # print(emo.emojify(text))
            except:
                print("Sorry, I did not get that")
    x = x + 1
    if (x >= current):
        bool = False
コード例 #24
0
def translate_subtitles_file(video_path, source_srt_file, to_lang, forced, hi):
    language_code_convert_dict = {
        'he': 'iw',
        'zt': 'zh-cn',
        'zh': 'zh-tw',
    }

    to_lang = alpha3_from_alpha2(to_lang)
    lang_obj = CustomLanguage.from_value(to_lang, "alpha3")
    if not lang_obj:
        lang_obj = Language(to_lang)
    if forced:
        lang_obj = Language.rebuild(lang_obj, forced=True)
    if hi:
        lang_obj = Language.rebuild(lang_obj, hi=True)

    logging.debug('BAZARR is translating in {0} this subtitles {1}'.format(
        lang_obj, source_srt_file))

    max_characters = 5000

    dest_srt_file = get_subtitle_path(
        video_path,
        language=lang_obj
        if isinstance(lang_obj, Language) else lang_obj.subzero_language(),
        extension='.srt',
        forced_tag=forced,
        hi_tag=hi)

    subs = pysubs2.load(source_srt_file, encoding='utf-8')
    lines_list = [x.plaintext for x in subs]
    joined_lines_str = '\n\n\n'.join(lines_list)

    logging.debug(
        'BAZARR splitting subtitles into {} characters blocks'.format(
            max_characters))
    lines_block_list = []
    translated_lines_list = []
    while len(joined_lines_str):
        partial_lines_str = joined_lines_str[:max_characters]

        if len(joined_lines_str) > max_characters:
            new_partial_lines_str = partial_lines_str.rsplit('\n\n\n', 1)[0]
        else:
            new_partial_lines_str = partial_lines_str

        lines_block_list.append(new_partial_lines_str)
        joined_lines_str = joined_lines_str.replace(new_partial_lines_str, '')

    logging.debug('BAZARR is sending {} blocks to Google Translate'.format(
        len(lines_block_list)))
    for block_str in lines_block_list:
        empty_first_line = False
        if block_str.startswith('\n\n\n'):
            # This happens when the first line of text in a subtitles file is an empty string
            empty_first_line = True

        try:
            translated_partial_srt_text = GoogleTranslator(
                source='auto',
                target=language_code_convert_dict.get(
                    lang_obj.alpha2,
                    lang_obj.alpha2)).translate(text=block_str)
        except Exception:
            logging.exception(
                f'BAZARR Unable to translate subtitles {source_srt_file}')
            return False
        else:
            if empty_first_line:
                # GoogleTranslate remove new lines at the beginning of the string, so we add it back.
                translated_partial_srt_text = '\n\n\n' + translated_partial_srt_text
            translated_partial_srt_list = translated_partial_srt_text.split(
                '\n\n\n')
            translated_lines_list += translated_partial_srt_list

    logging.debug(
        'BAZARR saving translated subtitles to {}'.format(dest_srt_file))
    for i, line in enumerate(subs):
        try:
            line.plaintext = translated_lines_list[i]
        except IndexError:
            logging.error(
                f'BAZARR is unable to translate malformed subtitles: {source_srt_file}'
            )
            return False
    subs.save(dest_srt_file)

    return dest_srt_file
コード例 #25
0
def test_inputs():
    with pytest.raises(exceptions.LanguageNotSupportedException):
        GoogleTranslator(source="", target="")

    with pytest.raises(exceptions.LanguageNotSupportedException):
        GoogleTranslator(source="auto", target="nothing")
コード例 #26
0
def googletranslate_en(list_of_strings):
    return GoogleTranslator('auto', 'en').translate_batch(list_of_strings)
コード例 #27
0
# set to true when translating category names
translate_category_names = False
translate_shop_names = False

# load data files
train_data = pd.read_csv("data/sales_train.csv")
item_data = pd.read_csv("data/items.csv")
category_names = pd.read_csv("data/item_categories.csv")
item_names = pd.read_csv("data/items.csv")
shop_names = pd.read_csv("data/shops.csv")
prediction_data = pd.read_csv("data/test.csv")

# translate category names using google translate
if translate_category_names:
    translator = GoogleTranslator(source='ru', target='en')
    category_names["item_category_name"] = category_names[
        "item_category_name"].progress_apply(lambda x: translator.translate(x))
    category_names.to_csv("data/item_categories.csv", index=False)

# translate shop names using google translate
if translate_shop_names:
    translator = GoogleTranslator(source='ru', target='en')
    shop_names["shop_name"] = shop_names["shop_name"].progress_apply(
        lambda x: translator.translate(x))
    shop_names.to_csv("data/shops.csv", index=False)

# convert price to euros
train_data["item_price"] = train_data["item_price"] * 0.012
train_data["item_price"] = train_data["item_price"].round(2)
コード例 #28
0
ファイル: skrijBesedilo.py プロジェクト: mcentrih/CPSystems
        print('Povedali ste: ' + besedilo)
        engine.say('Povedali ste. ' + besedilo)
        engine.runAndWait()
    except st.UnknownValueError : 
        print("Se opravičujem, nisem razumel!")
        engine.say("Se opravičujem, nisem razumel!")
        engine.runAndWait()
    except st.RequestError :
        print('Preverite internetno povezavo')
    
    return besedilo

msg = posnamiBesedilo('Pozdravljeni! Povejte besedilo, ki ga želite skriti!')
print(msg)

translated = GoogleTranslator(source='auto', target='sl').translate(msg)
print("Prevedeno: " + translated)

engine.say("Vaše končno prevedeno besedilo je " + translated)
engine.runAndWait()

#for voice in voices:
#   engine.setProperty('voice', voice.id)
#   rate = engine.getProperty('rate')
#   engine.setProperty('rate', rate-50)

   #print("Voice: %s" % voice.name)
   #print(" - ID: %s" % voice.id)
   #print(" - Languages: %s" % voice.languages)
   #print(" - Gender: %s" % voice.gender)
   #print(" - Age: %s" % voice.age)
コード例 #29
0
try:
    # Just pass a language parameter
    out = r.recognize_sphinx(audio, language="en-US")
    massslov.append(out)
except sr.UnknownValueError:
    print("Sphinx could not understand audio")
except sr.RequestError as e:
    print("Sphinx error; {0}".format(e))

print("--- %s seconds ---" % (time.time() - start_time))
print(massslov)

from deep_translator import GoogleTranslator

to_translate = massslov[0]
translated = GoogleTranslator(source='auto',
                              target='ru').translate(to_translate)

print(translated)

from gtts import gTTS
import os

text = translated

language = 'ru'

speech = gTTS(text=text, lang=language, slow=False)

speech.save("text.mp3")

#os.system("start text.mp3")
コード例 #30
0
ファイル: videodub.py プロジェクト: 07gaura/python-projects
video = moviepy.editor.VideoFileClip("test2.mkv")
audio1 = video.audio
audio1.write_audiofile("2.wav")

sound = "2.wav"
r = sr.Recognizer()
with sr.AudioFile(sound) as source:
    r.adjust_for_ambient_noise(source)
    print("converting audio file to text....")

    audio = r.listen(source)

    try:
        print("Converted Audio is: \n" + r.recognize_google(audio))
        textaud = r.recognize_google(audio)
    except Exception as e:
        print(e)

trans = GoogleTranslator(source='auto', target='hi').translate(textaud)

language = 'hi'
output = gTTS(text=trans, lang=language, slow=False)
output.save("output.mp3")
os.system("start output.mp3")
clip = VideoFileClip("test2.mkv")

audioclip = AudioFileClip('output.mp3')
videoclip = clip.set_audio(audioclip)
videoclip.write_videofile("testingvid.webm")