Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 52 additions & 3 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,55 @@
from flask import Flask
from flask import Flask, request
import os
import openai

app = Flask(__name__)
openai.api_key = 'YOUR_OPEN_AI_KEY'

@app.route('/')
def hello_world():
return 'Hello, World!'
def index():
return """
<html>
<body>
<button onclick="startRecording()">Start Recording</button>
<button onclick="stopRecording()">Stop Recording</button>
<script>
let rec;
let audioChunks = [];

function startRecording() {
audioChunks = [];
rec = new MediaRecorder(window.stream);
rec.ondataavailable = e => {
audioChunks.push(e.data);
};
rec.start();
}

function stopRecording() {
rec.stop();
const audioBlob = new Blob(audioChunks);
const reader = new FileReader();
reader.readAsDataURL(audioBlob);
reader.onloadend = () => {
const base64data = reader.result;
fetch('/transcribe', {
method: 'POST',
body: JSON.stringify({ data: base64data }),
headers: { 'Content-Type': 'application/json' }
}).then(response => response.text()).then(data => {
console.log(data);
});
};
}
</script>
</body>
</html>
"""

@app.route('/transcribe', methods=['POST'])
def transcribe_audio():
audio_data = request.json['data']
# Here you need to convert the base64 audio data into a format suitable for the OpenAI API.
# This will likely involve writing the data to a file, or converting it to the correct audio format.
transcript = openai.Audio.transcribe("whisper-1", audio_data)
return transcript