Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
botbahlul authored Feb 14, 2023
1 parent 94c4120 commit 92924f1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 19 deletions.
36 changes: 19 additions & 17 deletions pyautosrt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
# ADDTIONAL IMPORTS
import io
import time
import signal
import threading
from threading import Timer, Thread
import PySimpleGUI as sg
Expand Down Expand Up @@ -565,22 +564,24 @@ def find_speech_regions(filename, frame_width=4096, min_region_size=0.3, max_reg
return regions


async def GoogleTranslate(text, src, dst):
def GoogleTranslate(text, src, dst):
url = 'https://translate.googleapis.com/translate_a/'
params = 'single?client=gtx&sl='+src+'&tl='+dst+'&dt=t&q='+text;
async with httpx.AsyncClient() as client:
response = await client.get(url+params)
#print('response = {}'.format(response))
response_json = response.json()[0]
#print('response_json = {}'.format(response_json))
length = len(response_json)
#print('length = {}'.format(length))
translation = ""
for i in range(length):
#print("{} {}".format(i, response_json[i][0]))
translation = translation + response_json[i][0]
return translation

with httpx.Client(http2=True) as client:
client.headers.update({'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)', 'Referer': 'https://translate.google.com',})
response = client.get(url+params)
#print('response.status_code = {}'.format(response.status_code))
if response.status_code == 200:
response_json = response.json()[0]
#print('response_json = {}'.format(response_json))
length = len(response_json)
#print('length = {}'.format(length))
translation = ""
for i in range(length):
#print("{} {}".format(i, response_json[i][0]))
translation = translation + response_json[i][0]
return translation
return

class SentenceTranslator(object):
def __init__(self, src, dest, patience=-1):
Expand All @@ -593,7 +594,9 @@ def __call__(self, sentence):
# handle the special case: empty string.
if not sentence:
return None
translated_sentence = asyncio.get_event_loop().run_until_complete(GoogleTranslate(sentence, src=self.src, dst=self.dest)) # using self made GoogleTranslate2()

translated_sentence = GoogleTranslate(sentence, src=self.src, dst=self.dest)

fail_to_translate = translated_sentence[-1] == '\n'
while fail_to_translate and patience:
translated_sentence = translator.translate(translated_sentence, src=self.src, dest=self.dest).text
Expand All @@ -607,7 +610,6 @@ def __call__(self, sentence):


def transcribe(src, dest, filename, subtitle_format, main_window):
#global thread_transcribe, not_transcribing, pool, wav_filename, subtitle_file, translated_subtitle_file, subtitle_folder_name, converter, recognizer, extracted_regions, transcriptions
global thread_transcribe, not_transcribing, pool

if not_transcribing: return
Expand Down
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

setup(
name="pyautosrt",
version="0.0.5",
version="0.0.6",
description="pyautosrt is a python based desktop app to generate subtitle and translated subtitle file",
long_description = long_description,
author="Bot Bahlul",
Expand All @@ -36,7 +36,6 @@
"six>=1.11.0",
"tk>=0.1.0",
"pysimplegui>=4.60.1",
"asyncio",
"httpx>=0.13.3",
],
license=open("LICENSE").read()
Expand Down

0 comments on commit 92924f1

Please sign in to comment.