Spaces:
Running
Running
mrfakename
commited on
Commit
•
1ace391
1
Parent(s):
562a7ed
loudnorm
Browse files
app.py
CHANGED
@@ -5,6 +5,8 @@ import threading, time, uuid, sqlite3, shutil, os, random, asyncio, threading
|
|
5 |
from pathlib import Path
|
6 |
from huggingface_hub import CommitScheduler, delete_file, hf_hub_download
|
7 |
from gradio_client import Client
|
|
|
|
|
8 |
from detoxify import Detoxify
|
9 |
toxicity = Detoxify('original')
|
10 |
with open('harvard_sentences.txt') as f:
|
@@ -19,7 +21,7 @@ AVAILABLE_MODELS = {
|
|
19 |
'OpenVoice': 'openvoice',
|
20 |
'Pheme': 'pheme',
|
21 |
'MetaVoice': 'metavoice',
|
22 |
-
'OpenAI': 'openai',
|
23 |
}
|
24 |
|
25 |
SPACE_ID = os.getenv('HF_ID')
|
@@ -469,7 +471,12 @@ with gr.Blocks() as leaderboard:
|
|
469 |
# bothgood.click(both_good, outputs=outputs, inputs=[model1, model2, useridstate])
|
470 |
|
471 |
# vote.load(reload, outputs=[aud1, aud2, model1, model2])
|
472 |
-
|
|
|
|
|
|
|
|
|
|
|
473 |
############
|
474 |
# 2x speedup (hopefully)
|
475 |
############
|
@@ -490,6 +497,7 @@ def synthandreturn(text):
|
|
490 |
print("[debug] Using", mdl1, mdl2)
|
491 |
def predict_and_update_result(text, model, result_storage):
|
492 |
result = router.predict(text, AVAILABLE_MODELS[model], api_name="/synthesize")
|
|
|
493 |
result_storage[model] = result
|
494 |
results = {}
|
495 |
thread1 = threading.Thread(target=predict_and_update_result, args=(text, mdl1, results))
|
|
|
5 |
from pathlib import Path
|
6 |
from huggingface_hub import CommitScheduler, delete_file, hf_hub_download
|
7 |
from gradio_client import Client
|
8 |
+
import pyloudnorm as pyln
|
9 |
+
import soundfile as sf
|
10 |
from detoxify import Detoxify
|
11 |
toxicity = Detoxify('original')
|
12 |
with open('harvard_sentences.txt') as f:
|
|
|
21 |
'OpenVoice': 'openvoice',
|
22 |
'Pheme': 'pheme',
|
23 |
'MetaVoice': 'metavoice',
|
24 |
+
'OpenAI TTS': 'openai',
|
25 |
}
|
26 |
|
27 |
SPACE_ID = os.getenv('HF_ID')
|
|
|
471 |
# bothgood.click(both_good, outputs=outputs, inputs=[model1, model2, useridstate])
|
472 |
|
473 |
# vote.load(reload, outputs=[aud1, aud2, model1, model2])
|
474 |
+
def doloudnorm(path):
|
475 |
+
data, rate = sf.read(path)
|
476 |
+
meter = pyln.Meter(rate)
|
477 |
+
loudness = meter.integrated_loudness(data)
|
478 |
+
loudness_normalized_audio = pyln.normalize.loudness(data, loudness, -12.0)
|
479 |
+
sf.write(path, loudness_normalized_audio, rate)
|
480 |
############
|
481 |
# 2x speedup (hopefully)
|
482 |
############
|
|
|
497 |
print("[debug] Using", mdl1, mdl2)
|
498 |
def predict_and_update_result(text, model, result_storage):
|
499 |
result = router.predict(text, AVAILABLE_MODELS[model], api_name="/synthesize")
|
500 |
+
doloudnorm(result)
|
501 |
result_storage[model] = result
|
502 |
results = {}
|
503 |
thread1 = threading.Thread(target=predict_and_update_result, args=(text, mdl1, results))
|