change topurch audio to soundfile

This commit is contained in:
Wolfang Torres
2026-06-25 21:25:49 +08:00
parent d153a441ed
commit 5896f0db66
2 changed files with 5 additions and 5 deletions

View File

@@ -31,7 +31,7 @@ dependencies = [
"genanki", "genanki",
"argostranslate", "argostranslate",
"torch", "torch",
"torchaudio", "soundfile",
"torchcodec", "torchcodec",
"python-dotenv", "python-dotenv",
"qwen-tts", "qwen-tts",

View File

@@ -5,7 +5,7 @@ import csv
# Pip # Pip
import argostranslate.translate import argostranslate.translate
import torchaudio import soundfile as sf
# Local # Local
from .constants import LANGUAGES from .constants import LANGUAGES
@@ -32,7 +32,7 @@ def dictation_process(
audio_path = process_file.resources / f"N{n:03n}.wav" audio_path = process_file.resources / f"N{n:03n}.wav"
if not audio_path.exists(): if not audio_path.exists():
wavs, sr = TTS.generate(f"{audio_line}") wavs, sr = TTS.generate(f"{audio_line}")
torchaudio.save(audio_path, wavs[0], sr) sf.write(audio_path, wavs[0], sr)
translated = argostranslate.translate.translate( translated = argostranslate.translate.translate(
line, LANGUAGES.CN, process_file.language_id line, LANGUAGES.CN, process_file.language_id
) )
@@ -55,7 +55,7 @@ def translator_process(
audio_path = process_file.resources / f"N{n:03n}.wav" audio_path = process_file.resources / f"N{n:03n}.wav"
if not audio_path.exists(): if not audio_path.exists():
wavs, sr = TTS.generate(f"{audio_line}") wavs, sr = TTS.generate(f"{audio_line}")
torchaudio.save(audio_path, wavs[0], sr) sf.write(audio_path, wavs[0], sr)
translated = argostranslate.translate.translate( translated = argostranslate.translate.translate(
line, LANGUAGES.CN, process_file.language_id line, LANGUAGES.CN, process_file.language_id
) )
@@ -118,7 +118,7 @@ def dictionary_process(process_file: ProcessFile) -> list[DictionaryResult]:
audio_path = process_file.resources / f"{line['pinyin']}.wav" audio_path = process_file.resources / f"{line['pinyin']}.wav"
if not audio_path.exists(): if not audio_path.exists():
wavs, sr = TTS.generate(f"{line['simplified']}") wavs, sr = TTS.generate(f"{line['simplified']}")
torchaudio.save(audio_path, wavs[0], sr) sf.write(audio_path, wavs[0], sr)
print(line) print(line)
result = DictionaryResult( result = DictionaryResult(
**line, audio_path=audio_path, language_id=process_file.language_id **line, audio_path=audio_path, language_id=process_file.language_id