-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
64 lines (43 loc) · 2.06 KB
/
app.py
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
57
58
59
60
61
62
63
64
# from flask import Flask, render_template, request, jsonify
# from azure_speech_to_text import SpeechToTextManager
# import threading # Add this line to import the threading module
# import subprocess # Add this line to import subprocess module
# import os
# app = Flask(__name__)
# speechtotext_manager = SpeechToTextManager()
# def takecommand():
# return speechtotext_manager.speechtotext_from_mic_continuous()
# listening_thread = None # Define listening_thread globally
# @app.route('/')
# def index():
# return render_template('index.html')
# character = ""
# @app.route('/set_character', methods=['POST'])
# def set_character():
# global character
# character = request.json['character']
# # Optionally, you can store the character name in a global variable or session for later use
# return jsonify({'status': 'success'})
# def takecommand_and_process():
# global mic_result
# mic_result = takecommand()
# if mic_result:
# # Assuming you have a way to determine the character's name, let's say it's stored in a variable called 'character'
# character_ = character # Implement this function to determine the character's name
# # Call chatgpt_character.py passing the character's name and mic_result
# subprocess.run(['python', 'chatgpt_char.py', character_, mic_result])
# @app.route('/start_listening', methods=['POST'])
# def start_listening():
# global listening_thread
# listening_thread = threading.Thread(target=takecommand_and_process)
# listening_thread.start()
# return jsonify({'status': 'success'})
# @app.route('/stop_listening', methods=['POST'])
# def stop_listening():
# speechtotext_manager.stop_listening() # Signal the SpeechToTextManager to stop listening
# global listening_thread
# if listening_thread and listening_thread.is_alive():
# listening_thread.join() # Wait for the thread to complete
# return jsonify({'status': 'success'})
# if __name__ == '__main__':
# app.run(debug=True)