From 7eb80ddb73d670a314a0a61e22ed12d37495cf4c Mon Sep 17 00:00:00 2001 From: "suherdy.yacob@mapan.co.id" Date: Fri, 30 May 2025 14:11:01 +0700 Subject: [PATCH] fix some bug --- config.ini | 2 +- main.py | 2 +- main2.py | 2 +- main3.py | 2 +- output/Candra mas.MP3.txt | 0 output/Candra mas_113350_id.txt | 11 ++++++++ output/REC20250526103049.WAV.txt | 0 .../convert_to_mono.cpython-312.pyc | Bin 1683 -> 2673 bytes .../__pycache__/core_analysis.cpython-312.pyc | Bin 5303 -> 5303 bytes .../__pycache__/wav_segmenter.cpython-312.pyc | Bin 1657 -> 1692 bytes .../write_log_file.cpython-312.pyc | Bin 1487 -> 1404 bytes speechlib/convert_to_mono.py | 25 +++++++++++++++++- speechlib/wav_segmenter.py | 2 +- speechlib/write_log_file.py | 3 ++- 14 files changed, 42 insertions(+), 7 deletions(-) create mode 100644 output/Candra mas.MP3.txt create mode 100644 output/Candra mas_113350_id.txt create mode 100644 output/REC20250526103049.WAV.txt 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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&HdzW@LL diff --git a/speechlib/__pycache__/core_analysis.cpython-312.pyc b/speechlib/__pycache__/core_analysis.cpython-312.pyc index f66b136de331fa261b15e903be51ad7510a0fa26..47d38706b19169f555924a68c455a6d89ffb9a98 100644 GIT binary patch delta 19 Zcmdn4xm}a%G%qg~0}zBpY~)%i0su6s1mgez delta 19 Zcmdn4xm}a%G%qg~0}zBNZRA=j0su3d1g!u7 diff --git a/speechlib/__pycache__/wav_segmenter.cpython-312.pyc b/speechlib/__pycache__/wav_segmenter.cpython-312.pyc index a3a7205d07caca5a2d93562648aa2ed1b625abdb..fb1e46bb0d323535160ab9f8d18cdcc833f9a987 100644 GIT binary patch delta 282 zcmey#Gl!S=G%qg~0}x#BvCOzWk+*}HmzXjG~iOnN%6YCwns)O0QsHsNoJ~P-ZBRfElR5 zP$X6>Tp~SrI+Hx((aGDH9J#rQQ`2)(^GbB9YbP@@>oM|8Hel9aE#d%b*&M?h!^r48 zc_&M^qs?_?vx~}R8!ETgZ>&F1a@pMHM9@X^fa~UA7tO;ighyRAkG>ESd(k}ZvU2=I z{`f12DHl@HE+?j6L0^Kq*@wDLOfs$xwO@3quWeFoQBfi5SRO5Kv(#5~~$1 zk(|7qNuF`%A9(SCAyQPne~9idok;5u4ay5WOSc=gQeRxVnycq{FV7T zQZDN`A8@*;=YCz!_oANfiR8pE8lKqC-`c<*1dZ_xU1{Z;>-29G7laVoCvIL6*w;GVo0>s7t z7$zsPBq)4fV-S#P@OZ+`-Qh7I-$eYR-v$5Eiu|9>l3Mg2^1R_&dz-%xHWrJl?SV7{o ztR=!g3JhvkQ`lBBLD;oyDeSfEH4H8cvBp4E95oy%Op-vUT23H~1I*$AvN*vkZXk;b z%;KrxPGQfU{F_lqn7f8^HbV+e4HuB)t>Ffee3LbpoEiBi=P=ny3;0#Bsd}jTss{!WAqzPiH1BqK4Ho5sJr8%i~McR|2StU878TrAo E09Phe_y7O^ 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")