-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExtract.py
32 lines (21 loc) · 958 Bytes
/
Extract.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import os
import sqlite3
def extract_audio_from_db(input_filename, db_name="audio_files.db", output_folder="extracted_audio"):
if not os.path.exists(output_folder):
os.makedirs(output_folder)
conn = sqlite3.connect(db_name)
cursor = conn.cursor()
cursor.execute("SELECT filename FROM audio_files")
all_files = cursor.fetchall()
normalized_input_filename = input_filename.replace('.usm', '').lower() + '.aac'
cursor.execute("SELECT filename, audio FROM audio_files WHERE filename = ?", (normalized_input_filename,))
rows = cursor.fetchall()
if rows:
for row in rows:
filename, audio_data = row
output_path = os.path.join(output_folder, filename)
with open(output_path, 'wb') as f:
f.write(audio_data)
else:
print(f"Tidak ditemukan file audio yang cocok dengan {input_filename}")
conn.close()