01/10/2018, 12:37
Lỗi gọi lệnh python trong cmd không được
Chào các bạn!
Mình đang bị lỗi ko thể gọi lệnh trong cmd, khi viết lệnh xong thi máy nhảy lên trang python.exe rồi tắt đi không báo lỗi hay gì hết. Mình có file gif lỗi, nhờ các bạn xem nhé.
Tks!

Bài liên quan
Bạn thử cách của mình xem
Thiếu python ở trước.
Mình đã thử 2 cách của 2 bạn ròi, nhưng vẫn ko đc hjx…
Mình thấy chương trình python của bạn đã chạy, nên mình đoán trong lệnh của bạn chỉ là xử lý không có xuất màn hình gì cả. Bạn nên kiểm tra xem hoặc chèn thêm lệnh check vào code để kiểm tra.
Bạn ơi, sáng mai mình gửi câu lệnh qua bạn xem nhé. Tại mình cài vào máy bàn thì chạy đc, mà cài vào lap thì ko đc. Mình làm autosub bằng python mà ko đc, buồn hết sức
Minh gui ban lenh cua minh nhe, xem giup the nao nhe.
#!c:\python27\python.exe
import argparse
import audioop
from googleapiclient.discovery import build
import json
import math
import multiprocessing
import os
import requests
import subprocess
import sys
import tempfile
import wave
from progressbar import ProgressBar, Percentage, Bar, ETA
from autosub.constants import LANGUAGE_CODES,
GOOGLE_SPEECH_API_KEY, GOOGLE_SPEECH_API_URL
from autosub.formatters import FORMATTERS
def percentile(arr, percent):
arr = sorted(arr)
k = (len(arr) - 1) * percent
f = math.floor(k)
c = math.ceil(k)
if f == c: return arr[int(k)]
d0 = arr[int(f)] * (c - k)
d1 = arr[int©] * (k - f)
return d0 + d1
def is_same_language(lang1, lang2):
return lang1.split("-")[0] == lang2.split("-")[0]
class FLACConverter(object):
def init(self, source_path, include_before=0.25, include_after=0.25):
self.source_path = source_path
self.include_before = include_before
self.include_after = include_after
class SpeechRecognizer(object):
def init(self, language=“en”, rate=44100, retries=3, api_key=GOOGLE_SPEECH_API_KEY):
self.language = language
self.rate = rate
self.api_key = api_key
self.retries = retries
class Translator(object):
def init(self, language, api_key, src, dst):
self.language = language
self.api_key = api_key
self.service = build(‘translate’, ‘v2’,
developerKey=self.api_key)
self.src = src
self.dst = dst
def which(program):
def is_exe(fpath):
return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
def extract_audio(filename, channels=1, rate=16000):
temp = tempfile.NamedTemporaryFile(suffix=’.wav’, delete=False)
if not os.path.isfile(filename):
print “The given file does not exist: {0}”.format(filename)
raise Exception(“Invalid filepath: {0}”.format(filename))
if not which(“ffmpeg”):
print “ffmpeg: Executable not found on machine.”
raise Exception(“Dependency not found: ffmpeg”)
command = [“ffmpeg”, “-y”, “-i”, filename, “-ac”, str(channels), “-ar”, str(rate), “-loglevel”, “error”, temp.name]
subprocess.check_output(command, stdin=open(os.devnull))
return temp.name, rate
def find_speech_regions(filename, frame_width=4096, min_region_size=0.5, max_region_size=6):
reader = wave.open(filename)
sample_width = reader.getsampwidth()
rate = reader.getframerate()
n_channels = reader.getnchannels()
def main():
parser = argparse.ArgumentParser()
parser.add_argument(‘source_path’, help=“Path to the video or audio file to subtitle”, nargs=’?’)
parser.add_argument(’-C’, ‘–concurrency’, help=“Number of concurrent API requests to make”, type=int, default=10)
parser.add_argument(’-o’, ‘–output’,
help=“Output path for subtitles (by default, subtitles are saved in
the same directory and name as the source path)”)
parser.add_argument(’-F’, ‘–format’, help=“Destination subtitle format”, default=“srt”)
parser.add_argument(’-S’, ‘–src-language’, help=“Language spoken in source file”, default=“en”)
parser.add_argument(’-D’, ‘–dst-language’, help=“Desired language for the subtitles”, default=“en”)
parser.add_argument(’-K’, ‘–api-key’,
help=“The Google Translate API key to be used. (Required for subtitle translation)”)
parser.add_argument(’–list-formats’, help=“List all available subtitle formats”, action=‘store_true’)
parser.add_argument(’–list-languages’, help=“List all available source/destination languages”, action=‘store_true’)
if name == ‘main’:
sys.exit(main())
Xin lỗi bạn mình hơi nhiều chuyện vì mình mới tập tễnh vào học python được mấy ngày. Nhưng lỗi theo như bạn nói thì chạy được trên laptop nhưng không chạy được trên máy bàn có thể do hai nguyên nhân.
Do trình biên dịch:
Python trong file bạn đang phiên bản 2.7, bạn kiểm tra lại xem phiên bản mình đang sử dụng có trùng khớp không, vì có thể thay đổi một số lệnh trong đó.
Do môi trường máy
Có thể máy laptop và máy bàn của bạn đang sử dụng hai môi trường khác nhau, có dẫn đến file chạy không chính xác.
Lỗi khác, do API dịch chẳng hạn, do mình chưa học nhiều nên không thể đọc source code của bạn được. Nhưng với cách chạy trên cmd thông thường như mình bên trên thì mình không gặp vấn đề nào cả.
Bạn có thể thử 1 trong hai hướng.
Thay code nó bằng code bên dưới
https://github.com/agermanidis/autosub/blob/master/bin/autosub
Tìm kiếm hướng dẫn giải quyết trong link dưới
https://github.com/agermanidis/autosub/issues/31