File size: 1,948 Bytes
90440c8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from pydub.utils import mediainfo
import hashlib

def audio_hash(audio_path):
    with open(audio_path, "rb") as f:
        audio_data = f.read()
    hash_object = hashlib.sha256()
    hash_object.update(audio_data)
    audio_hash = hash_object.hexdigest()
    
    return audio_hash[:10]

def str_to_hash(input_str):
    input_bytes = input_str.encode('utf-8')
    hash_object = hashlib.sha256()
    hash_object.update(input_bytes)
    hash_code = hash_object.hexdigest()
    
    return hash_code[:10]

def get_unique_code(reference_speaker, text, language):
    return f"{audio_hash(reference_speaker)}_{str_to_hash(text)}_{language}"

if __name__ == '__main__':

    example_inputs = [
        {
            "text": "The bustling city square bustled with street performers, tourists, and local vendors.",
            "language": 'en_us',
            "reference_speaker": "examples/speaker0.mp3"
        },
        {
            "text": "Did you ever hear a folk tale about a giant turtle?",
            "language": 'en_us',
            "reference_speaker": "examples/speaker0.mp3"
        },
        {
            "text": "El resplandor del sol acaricia las olas, pintando el cielo con una paleta deslumbrante.",
            "language": 'es_default',
            "reference_speaker": "examples/speaker1.mp3",
        },
        {
            "text": "我最近在学习machine learning,希望能够在未来的artificial intelligence领域有所建树。",
            "language": 'zh_default',
            "reference_speaker": "examples/speaker2.mp3",
        },
        {
            "text": "彼は毎朝ジョギングをして体を健康に保っています。",
            "language": 'jp_default',
            "reference_speaker": "examples/speaker3.mp3",
        }
    ]

    for example_input in example_inputs:
        print(get_unique_code(example_input['reference_speaker'], example_input['text'], example_input['language']))