File size: 1,599 Bytes
05b45a5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import requests
import os
import json

def main():
    # Test phoneme string
    phonemes = "hˈɛloʊ wˈɜrld"  # "Hello world" in phonemes
    
    try:
        print("\nTesting phoneme generation via API...")
        
        # Create request payload
        payload = {
            "phonemes": phonemes,
            "voice": "af_bella"  # Using bella voice
        }
        
        # Make request to the API endpoint
        response = requests.post(
            "http://localhost:8880/dev/generate_from_phonemes",
            json=payload,
            stream=True  # Enable streaming for audio data
        )
        
        # Check if request was successful
        if response.status_code == 200:
            # Create output directory if it doesn't exist
            os.makedirs("examples/phoneme_examples/output", exist_ok=True)
            
            # Save the audio response
            output_path = 'examples/phoneme_examples/output/phoneme_test.wav'
            with open(output_path, 'wb') as f:
                for chunk in response.iter_content(chunk_size=8192):
                    if chunk:
                        f.write(chunk)
            
            print(f"\nAudio saved to: {output_path}")
            print("\nPhoneme test completed successfully!")
            print(f"\nInput phonemes: {phonemes}")
        else:
            print(f"Error: API request failed with status code {response.status_code}")
            print(f"Response: {response.text}")
    
    except Exception as e:
        print(f"An error occurred: {str(e)}")

if __name__ == "__main__":
    main()