-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
50 lines (40 loc) · 1.62 KB
/
main.py
File metadata and controls
50 lines (40 loc) · 1.62 KB
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
from flask import Flask, request, jsonify
import soundfile as sf
import io
import transcriber
from pydub import AudioSegment
import numpy as np
import os
import uuid
app = Flask(__name__)
UPLOAD_FOLDER = 'uploads'
os.makedirs(UPLOAD_FOLDER, exist_ok=True)
@app.route('/transcribe', methods=['POST'])
def transcribe():
if 'file' not in request.files:
return jsonify({'error': 'No file part'}), 400
file = request.files['file']
if file.filename == '':
return jsonify({'error': 'No selected file'}), 400
if file:
# Generate a unique filename to avoid collisions
unique_filename = str(uuid.uuid4()) + os.path.splitext(file.filename)[1]
filepath = os.path.join(UPLOAD_FOLDER, unique_filename)
# Save the file
file.save(filepath)
# Pass the file path to the transcriber
transcription = transcriber.transcribe(filepath)
# Optionally, delete the file after transcription
# os.remove(filepath)
# Call the internal transcribe function
transcription = transcriber.transcribe(filepath)
return jsonify({'transcription': transcription})
else:
return jsonify({'error': 'Invalid file format'}), 400
@app.route('/multilingual', methods=['POST'])
def recognize_multilingual():
# Implement your code here to handle the audio transcription for multilingual content
# You can access the audio file and other parameters from request.files and request.form
return jsonify({'transcription': 'Transcribed text goes here'})
if __name__ == '__main__':
app.run(port=5000, debug=True)