File size: 2,576 Bytes
4a39464
 
 
 
 
 
 
 
 
6fd1f87
4a39464
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6fd1f87
4a39464
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6fd1f87
4a39464
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
"""
Примеры использования Audio Enhancer API
"""

import requests


def enhance_audio_example():
    """Пример полной обработки аудио"""
    url = "http://localhost:7860/enhance"

    with open("audio.mp3", "rb") as f:
        files = {"file": f}
        data = {
            "noise_reduction": True,
            "normalize_volume": True,
            "enhance_speech": True,
            "remove_silence": True,
            "target_sample_rate": 16000,
        }

        response = requests.post(url, files=files, data=data)

    if response.status_code == 200:
        with open("enhanced.wav", "wb") as f:
            f.write(response.content)
        print("✅ Аудио успешно обработано: enhanced.wav")
    else:
        print(f"❌ Ошибка: {response.status_code}")
        print(response.text)


def denoise_only_example():
    """Пример быстрого шумоподавления"""
    url = "http://localhost:7860/denoise"

    with open("noisy_audio.mp3", "rb") as f:
        files = {"file": f}
        data = {
            "stationary": True,
            "prop_decrease": 0.8,
        }

        response = requests.post(url, files=files, data=data)

    if response.status_code == 200:
        with open("denoised.wav", "wb") as f:
            f.write(response.content)
        print("✅ Шумоподавление завершено: denoised.wav")
    else:
        print(f"❌ Ошибка: {response.status_code}")
        print(response.text)


def health_check_example():
    """Проверка работоспособности сервиса"""
    url = "http://localhost:7860/health"

    response = requests.get(url)

    if response.status_code == 200:
        data = response.json()
        print(f"✅ Сервис работает")
        print(f"   Статус: {data['status']}")
        print(f"   Silero VAD: {data['silero_vad_loaded']}")
    else:
        print(f"❌ Сервис недоступен: {response.status_code}")


if __name__ == "__main__":
    print("=== Audio Enhancer API Examples ===\n")

    print("1. Проверка работоспособности")
    health_check_example()
    print()

    print("2. Полная обработка аудио")
    # enhance_audio_example()
    print("   (раскомментируйте для запуска)")
    print()

    print("3. Быстрое шумоподавление")
    # denoise_only_example()
    print("   (раскомментируйте для запуска)")