File size: 1,351 Bytes
2fbe5c7
64fefd1
 
 
d27c425
7f1b8f0
 
 
2fbe5c7
7f1b8f0
2fbe5c7
cee70e1
 
 
 
 
7f1b8f0
851bf2f
7f1b8f0
 
 
 
 
 
 
 
2fbe5c7
 
 
7f1b8f0
 
 
 
cee70e1
 
2fbe5c7
7f1b8f0
 
 
6cc6d47
7f1b8f0
2fbe5c7
 
7f1b8f0
 
 
 
6cc6d47
7f1b8f0
052339c
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
import os

from flask import Flask, request, send_file, jsonify, make_response, render_template

from gradio_client import Client
import tempfile



app = Flask(__name__)

def process_input(input_text):
    # 处理函数
    result = "Processed: " + input_text
    return result

@app.route('/', methods=["POST"])

def api():
     # try:
        if 'audio' not in request.files:
            return jsonify({"error": "No audio file provided"})

        file = request.files['audio']
        filename = request.form.get('filename')

        # Create a temporary directory
        temp_dir = tempfile.mkdtemp()

        # Save the audio file to the temporary directory with the specified filename and .wav extension
        destination_path = os.path.join(temp_dir, f"{filename}.wav")
        file.save(destination_path)
        print(destination_path)
        
        client = Client("https://xxiani-speechbrain-asr-wav2vec2-transformer-aishells.hf.space/")
        result = client.predict(
             
                        destination_path,	# str (filepath or URL to file) in 'Input' Audio component
                        api_name="/predict"
        )

        os.remove(destination_path)
        os.rmdir(temp_dir)
        return jsonify({'result': result})




if __name__ == '__main__':
    app.run(host='0.0.0.0', port=23456, debug=False)