018 019 020 zu mp3

This commit is contained in:
2025-05-31 19:47:07 +02:00
parent fbfc38e9e5
commit 7574870c84
119 changed files with 66 additions and 147 deletions

View File

@@ -1,48 +1,87 @@
import json
import uuid
import hashlib
with open('deck.json', 'r', encoding='utf-8') as f:
base91chars = (
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
'0123456789!#$%&()*+,-./:;<=>?@[]^_`{|}~'
)
def anki_guid(text: str) -> str:
# SHA1-Hash des Front-Felds berechnen
h = hashlib.sha1(text.encode('utf-8')).digest()
x = int.from_bytes(h[:8], 'little') # Anki nimmt die ersten 8 Bytes, little-endian
# Kodierung in Base91-Zeichenkette (10 Zeichen)
chars = []
for _ in range(10):
chars.append(base91chars[x % len(base91chars)])
x //= len(base91chars)
return ''.join(chars)
with open('Schwedisch_Goetheverlag/deck.json', 'r', encoding='utf-8') as f:
data = json.load(f)
original_notes = data['notes']
new_notes = []
existing_signatures = set()
def signature(front0, front1, back):
return f"{front0}||{front1}||{back}"
existing__notemodels = []
for i in data['note_models']:
existing__notemodels.append(i['crowdanki_uuid'])
for note in original_notes:
fields = note['fields']
note_model_uuid = note['note_model_uuid']
if len(fields) < 3:
continue
original_front = fields[0] # "ich"
original_back = fields[1] # "jag"
original_audio = fields[2] # "[sound:Jag-4718d0.mp3]"
original_back_audio = fields[2] # "[sound:Jag-4718d0.mp3]"
original_front_uuid = note_model_uuid
new_uuid = None
new_note = None
sig = signature(original_front, original_audio, original_back)
reversed_sig = signature(original_back, original_audio, original_front)
if note['guid'].startswith('rev-') or reversed_sig in existing_signatures:
continue
if original_front_uuid == existing__notemodels[0]:
# Original:
# Deutsch (Front)
# Sverige (Back)
# Audio (Backaudio)
# Neu:
# Sverige (Front)
# Audio (Frontaudio)
# Deutsch (Back)
new_note = {
"__type__": "Note",
"fields": [
original_back, # Feld 0: Frage Text (Antwort aus Original)
original_audio, # Feld 1: Frage Audio (MP3 aus Original)
original_front # Feld 2: Antwort Text (Frage aus Original)
original_back,
original_back_audio,
original_front
],
"guid": f"rev-{uuid.uuid4()}",
"note_model_uuid": note["note_model_uuid"],
"tags": note.get("tags", []) + ["reversed"]
"guid": f"{anki_guid(original_back)}",
"note_model_uuid": existing__notemodels[1],
"tags": []
}
new_notes.append(new_note)
existing_signatures.add(sig)
existing_signatures.add(reversed_sig)
# new_note = {
# "__type__": "Note",
# "fields": [
# original_front,
# original_front_audio,
# original_back
# ],
# "guid": f"{anki_guid(original_front)}",
# "note_model_uuid": note_model_uuid[1]
# }
# new_notes.append(new_note)
# print(new_note
data['notes'].extend(new_notes)
with open('crowdanki_export_dupliziert.json', 'w', encoding='utf-8') as f:
with open('Schwedisch_Goetheverlag/crowdanki_export_dupliziert.json', 'w', encoding='utf-8') as f:
json.dump(data, f, ensure_ascii=False, indent=2)

View File

@@ -1,4 +1,4 @@
import hashlib, uuid, random, string
import hashlib, uuid, random, string, sys
def anki_guid1(text: str) -> str:
#return hashlib.sha1(text.encode('utf-8')).hexdigest()[:10]
@@ -35,4 +35,4 @@ def anki_guid(text: str) -> str:
return ''.join(chars)
print(anki_guid("ich und du"))
print(anki_guid(sys.argv[1]))

Binary file not shown.

Binary file not shown.

View File

@@ -1,21 +0,0 @@
#!/usr/bin/python3
# coding=utf-8
from pydub import AudioSegment
import sys,os
def convert(wav):
# Lade die WAV-Datei
audio = AudioSegment.from_wav(wav)
print(wav)
output = os.path.splitext(wav)[0]
outputname = output+".mp3"
# print(outputname)
# Speichere sie als MP3 (z.B. mit einer Bitrate von 192 kbps)
audio.export(outputname, format="mp3", bitrate="192k")
print("Konvertierung abgeschlossen!")
convert(sys.argv[1])

View File

@@ -1,9 +0,0 @@
#!/bin/bash
for i in $(ls *.wav)
do
python3 convert.py $i
echo $i
rm -f $i
done

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -1,21 +0,0 @@
#!/usr/bin/python3
# coding=utf-8
from pydub import AudioSegment
import sys,os
def convert(wav):
# Lade die WAV-Datei
audio = AudioSegment.from_wav(wav)
print(wav)
output = os.path.splitext(wav)[0]
outputname = output+".mp3"
# print(outputname)
# Speichere sie als MP3 (z.B. mit einer Bitrate von 192 kbps)
audio.export(outputname, format="mp3", bitrate="192k")
print("Konvertierung abgeschlossen!")
convert(sys.argv[1])

View File

@@ -1,9 +0,0 @@
#!/bin/bash
for i in $(ls *.wav)
do
python3 convert.py $i
echo $i
rm -f $i
done

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -1,21 +0,0 @@
#!/usr/bin/python3
# coding=utf-8
from pydub import AudioSegment
import sys,os
def convert(wav):
# Lade die WAV-Datei
audio = AudioSegment.from_wav(wav)
print(wav)
output = os.path.splitext(wav)[0]
outputname = output+".mp3"
# print(outputname)
# Speichere sie als MP3 (z.B. mit einer Bitrate von 192 kbps)
audio.export(outputname, format="mp3", bitrate="192k")
print("Konvertierung abgeschlossen!")
convert(sys.argv[1])

View File

@@ -1,9 +0,0 @@
#!/bin/bash
for i in $(ls *.wav)
do
python3 convert.py $i
echo $i
rm -f $i
done

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -1,21 +0,0 @@
#!/usr/bin/python3
# coding=utf-8
from pydub import AudioSegment
import sys,os
def convert(wav):
# Lade die WAV-Datei
audio = AudioSegment.from_wav(wav)
print(wav)
output = os.path.splitext(wav)[0]
outputname = output+".mp3"
# print(outputname)
# Speichere sie als MP3 (z.B. mit einer Bitrate von 192 kbps)
audio.export(outputname, format="mp3", bitrate="192k")
print("Konvertierung abgeschlossen!")
convert(sys.argv[1])

View File

@@ -1,9 +0,0 @@
#!/bin/bash
for i in $(ls *.wav)
do
python3 convert.py $i
echo $i
rm -f $i
done

Some files were not shown because too many files have changed in this diff Show More