File size: 1,282 Bytes
4c77e7e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
import base64

import io
import requests
import numpy as np
from scipy.io import wavfile
from dotenv import load_dotenv


# Load environment variables
load_dotenv()


URL = os.getenv("URL")


# RAG API
def rag_api(query, audio_language_code):

    res = requests.post(f"{URL}/api/rag",
                        json={
                            'query': query,
                            'audio_language_code': audio_language_code
                        })

    return res.json()


# Agent + RAG API
def agent_api(query, audio_language_code):

    res = requests.post(f"{URL}/api/agent",
                        json={
                            'query': query,
                            'audio_language_code': audio_language_code
                        })

    return res.json()


def base64_to_audio(base64_string):

    try:
        # Decode the base64 string
        audio_data = base64.b64decode(base64_string)  # Decode
        audio_file = io.BytesIO(audio_data)  # Convert to BytesIO object

        sample_rate, samples = wavfile.read(audio_file)
        samples_array = np.array(samples)

        return sample_rate, samples_array
    except Exception as e:
        print(e)
        return None, None