Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add threshold to Parameter Line Commands #39

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions bin/autosub
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def extract_audio(filename, channels=1, rate=16000):
return temp.name, rate


def find_speech_regions(filename, frame_width=4096, min_region_size=0.5, max_region_size=6):
def find_speech_regions(filename, frame_width=4096, min_region_size=0.5, max_region_size=6,dthreshold=0.2):
reader = wave.open(filename)
sample_width = reader.getsampwidth()
rate = reader.getframerate()
Expand All @@ -137,7 +137,7 @@ def find_speech_regions(filename, frame_width=4096, min_region_size=0.5, max_reg
chunk = reader.readframes(frame_width)
energies.append(audioop.rms(chunk, sample_width * n_channels))

threshold = percentile(energies, 0.2)
threshold = percentile(energies, dthreshold)

elapsed_time = 0

Expand Down Expand Up @@ -175,9 +175,9 @@ def main():
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')

parser.add_argument('-T', '--threshold', help="Threshold,for level noise ", default=0.2,type=float)
args = parser.parse_args()

threshold = args.threshold
if args.list_formats:
print("List of formats:")
for subtitle_format in FORMATTERS.keys():
Expand Down Expand Up @@ -209,7 +209,7 @@ def main():

audio_filename, audio_rate = extract_audio(args.source_path)

regions = find_speech_regions(audio_filename)
regions = find_speech_regions(audio_filename,dthreshold = threshold)

pool = multiprocessing.Pool(args.concurrency)
converter = FLACConverter(source_path=audio_filename)
Expand Down