diff --git a/config.ini b/config.ini index d61badb..517dfd5 100644 --- a/config.ini +++ b/config.ini @@ -8,4 +8,4 @@ voicefolder = D:\Pythoncode\speechlib\voices beamsize = 5 batchsize = 4 accesstoken = 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 -quantization = False \ No newline at end of file +quantization = True \ No newline at end of file diff --git a/main.py b/main.py index a995f6f..8600bcd 100644 --- a/main.py +++ b/main.py @@ -38,6 +38,6 @@ for filename in os.listdir(audio_dir): filename = open(filepath, "w") ### transcribe ### - transcriptor = Transcriptor(audiofile, output_dir, language, modelSize, access_token, voicefolder, quantization) + transcriptor = Transcriptor(audiofile, filepath, language, modelSize, access_token, voicefolder, quantization) res = transcriptor.faster_whisper() \ No newline at end of file diff --git a/main2.py b/main2.py index acddd31..4e33d07 100644 --- a/main2.py +++ b/main2.py @@ -48,7 +48,7 @@ if st.button("Transcribe"): #filepath = os.path.join(outputfolder, os.path.basename(audiofilewithoutextension).split('/')[-1]+".txt") filepath = os.path.join(outputfolder, f"{outlet}-{crew_id}-{crew_name}-{date}-Transkrip.txt") print(f"Output file: {filepath}") - filename = open(filepath, "w") + #filename = open(filepath, "w") ### transcribe ### transcriptor = Transcriptor(path, filepath, language, modelSize, access_token, voicefolder, quantization) diff --git a/main3.py b/main3.py index 63b6c98..1e084f3 100644 --- a/main3.py +++ b/main3.py @@ -44,7 +44,7 @@ if st.button("Transcribe"): #filepath = os.path.join(outputfolder, os.path.basename(audiofilewithoutextension).split('/')[-1]+".txt") filepath = os.path.join(outputfolder2, f"{crew_id}-{crew_name}-{customer_name}-{date}-Transkrip.txt") print(f"Output file: {filepath}") - filename = open(filepath, "w") + #filename = open(filepath, "w") ### transcribe ### transcriptor = Transcriptor(path, filepath, language, modelSize, access_token, voicefolder, quantization) diff --git a/output/Candra mas.MP3.txt b/output/Candra mas.MP3.txt new file mode 100644 index 0000000..e69de29 diff --git a/output/Candra mas_113350_id.txt b/output/Candra mas_113350_id.txt new file mode 100644 index 0000000..57726aa --- /dev/null +++ b/output/Candra mas_113350_id.txt @@ -0,0 +1,11 @@ +WATI (2.1 : 3.3) : See ya. +WATI (6.3 : 9.9) : dari mapan cik mau kunjungan +WATI (10.6 : 14.3) : Oh iya silahkan masuk mbak. Tak cek dulu ya cik ya. +WATI (15.3 : 17.7) : Kita hitung dulu stoknya. +WATI (18.6 : 20.2) : Terima kasih. +WATI (21.6 : 38.1) : yang layan nih pesan-pesan tok ya cik ya onan-onan hujan terus ya hujan angin ini tinggal berapa itunya apa kemarin somek udang ya somek udang sama +DWI (27.9 : 29.5) : Terima kasih. +WATI (38.7 : 40.0) : itunya sampean +WATI (44.2 : 45.7) : Minya tinggal satu lho, Ci. +WATI (46.7 : 47.7) : Kita hitung ya. +WATI (51.1 : 52.8) : Mbak helmnya diambil aja. diff --git a/output/REC20250526103049.WAV.txt b/output/REC20250526103049.WAV.txt new file mode 100644 index 0000000..e69de29 diff --git a/speechlib/__pycache__/convert_to_mono.cpython-312.pyc b/speechlib/__pycache__/convert_to_mono.cpython-312.pyc index ebed5ba..d8e2e4d 100644 Binary files a/speechlib/__pycache__/convert_to_mono.cpython-312.pyc and b/speechlib/__pycache__/convert_to_mono.cpython-312.pyc differ diff --git a/speechlib/__pycache__/core_analysis.cpython-312.pyc b/speechlib/__pycache__/core_analysis.cpython-312.pyc index f66b136..47d3870 100644 Binary files a/speechlib/__pycache__/core_analysis.cpython-312.pyc and b/speechlib/__pycache__/core_analysis.cpython-312.pyc differ diff --git a/speechlib/__pycache__/wav_segmenter.cpython-312.pyc b/speechlib/__pycache__/wav_segmenter.cpython-312.pyc index a3a7205..fb1e46b 100644 Binary files a/speechlib/__pycache__/wav_segmenter.cpython-312.pyc and b/speechlib/__pycache__/wav_segmenter.cpython-312.pyc differ diff --git a/speechlib/__pycache__/write_log_file.cpython-312.pyc b/speechlib/__pycache__/write_log_file.cpython-312.pyc index f59ae70..5ae8d00 100644 Binary files a/speechlib/__pycache__/write_log_file.cpython-312.pyc and b/speechlib/__pycache__/write_log_file.cpython-312.pyc differ diff --git a/speechlib/convert_to_mono.py b/speechlib/convert_to_mono.py index 4d6b02b..f61a25c 100644 --- a/speechlib/convert_to_mono.py +++ b/speechlib/convert_to_mono.py @@ -1,8 +1,31 @@ import wave import numpy as np +import soundfile as sf + +def resave_audio(input_file, output_file): + """Loads an audio file and resaves it. + + Args: + input_file (str): Path to the input audio file. + output_file (str): Path to save the resaved audio file. + """ + try: + # Read the audio file + data, samplerate = sf.read(input_file) + + # Write the audio data to a new file + sf.write(output_file, data, samplerate) + print(f"Successfully resaved audio from '{input_file}' to '{output_file}'") + + except Exception as e: + print(f"Error processing audio: {e}") + def convert_to_mono(input_wav): - # Open the input WAV file + # Resave WAV file + resave_audio(input_wav, input_wav.split('.')[0] + "_pcm.wav") + input_wav = input_wav.split('.')[0] + "_pcm.wav" + with wave.open(input_wav, 'rb') as input_file: # Get the parameters of the input file params = input_file.getparams() diff --git a/speechlib/wav_segmenter.py b/speechlib/wav_segmenter.py index bef461a..699be2c 100644 --- a/speechlib/wav_segmenter.py +++ b/speechlib/wav_segmenter.py @@ -23,7 +23,7 @@ def wav_file_segmentation(file_name, segments, language, modelSize, model_type, end = segment[1] * 1000 # end time in miliseconds clip = audio[start:end] i = i + 1 - file = folder_name + "/" + f"segment-{file_name.split("\\")[-1].split(".")[0]}"+ str(i) + ".wav" + file = folder_name + "/" + "segment-{}".format(file_name.split('\\')[-1].split(".")[0])+ str(i) + ".wav" clip.export(file, format="wav") try: diff --git a/speechlib/write_log_file.py b/speechlib/write_log_file.py index 0a18c8b..22a0e9e 100644 --- a/speechlib/write_log_file.py +++ b/speechlib/write_log_file.py @@ -12,7 +12,8 @@ def write_log_file(common_segments, log_folder, file_name, language): file_name = os.path.splitext(os.path.basename(file_name))[0] - log_file = log_folder + "/" + file_name + "_" + current_time + "_" + language + ".txt" + #log_file = log_folder + "/" + file_name + "_" + current_time + "_" + language + ".txt" + log_file = log_folder lf=open(log_file,"wb")