Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,6 +6,7 @@ from gtts import gTTS
|
|
| 6 |
from pydub import AudioSegment
|
| 7 |
from pydub.silence import detect_nonsilent
|
| 8 |
from waitress import serve
|
|
|
|
| 9 |
|
| 10 |
app = Flask(__name__)
|
| 11 |
|
|
@@ -57,6 +58,21 @@ def is_silent_audio(audio_path):
|
|
| 57 |
nonsilent_parts = detect_nonsilent(audio, min_silence_len=500, silence_thresh=audio.dBFS-16) # Reduced silence duration
|
| 58 |
return len(nonsilent_parts) == 0 # If no speech detected
|
| 59 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
@app.route("/")
|
| 61 |
def index():
|
| 62 |
return render_template("index.html")
|
|
@@ -83,7 +99,20 @@ def transcribe():
|
|
| 83 |
result = asr_model(output_audio_path, generate_kwargs={"language": "en"})
|
| 84 |
transcribed_text = result["text"].strip().capitalize()
|
| 85 |
|
| 86 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
except Exception as e:
|
| 88 |
return jsonify({"error": f"Speech recognition error: {str(e)}"}), 500
|
| 89 |
|
|
|
|
| 6 |
from pydub import AudioSegment
|
| 7 |
from pydub.silence import detect_nonsilent
|
| 8 |
from waitress import serve
|
| 9 |
+
from simple_salesforce import Salesforce
|
| 10 |
|
| 11 |
app = Flask(__name__)
|
| 12 |
|
|
|
|
| 58 |
nonsilent_parts = detect_nonsilent(audio, min_silence_len=500, silence_thresh=audio.dBFS-16) # Reduced silence duration
|
| 59 |
return len(nonsilent_parts) == 0 # If no speech detected
|
| 60 |
|
| 61 |
+
# Salesforce connection details
|
| 62 |
+
sf = Salesforce(username='diggavalli98@gmail.com', password='Sati@1020', security_token='sSSjyhInIsUohKpG8sHzty2q')
|
| 63 |
+
|
| 64 |
+
# Function to create Salesforce record
|
| 65 |
+
def create_salesforce_record(name, email, phone_number):
|
| 66 |
+
try:
|
| 67 |
+
customer_login = sf.Customer_Login__c.create({
|
| 68 |
+
'Name': name,
|
| 69 |
+
'Email__c': email,
|
| 70 |
+
'Phone_Number__c': phone_number
|
| 71 |
+
})
|
| 72 |
+
return customer_login
|
| 73 |
+
except Exception as e:
|
| 74 |
+
return {"error": f"Failed to create record in Salesforce: {str(e)}"}
|
| 75 |
+
|
| 76 |
@app.route("/")
|
| 77 |
def index():
|
| 78 |
return render_template("index.html")
|
|
|
|
| 99 |
result = asr_model(output_audio_path, generate_kwargs={"language": "en"})
|
| 100 |
transcribed_text = result["text"].strip().capitalize()
|
| 101 |
|
| 102 |
+
# Now, let's split the transcribed text into name, email, and phone number (basic example)
|
| 103 |
+
parts = transcribed_text.split() # This is a simplistic approach; you may need a better parsing mechanism
|
| 104 |
+
name = parts[0] # Assuming first word is the name
|
| 105 |
+
email = parts[1] if '@' in parts[1] else "unknown@domain.com" # Very basic email extraction
|
| 106 |
+
phone_number = parts[2] if len(parts) > 2 else "0000000000" # Basic phone number assumption
|
| 107 |
+
|
| 108 |
+
# Create record in Salesforce
|
| 109 |
+
salesforce_response = create_salesforce_record(name, email, phone_number)
|
| 110 |
+
|
| 111 |
+
if "error" in salesforce_response:
|
| 112 |
+
return jsonify(salesforce_response), 500
|
| 113 |
+
|
| 114 |
+
return jsonify({"text": transcribed_text, "salesforce_record": salesforce_response})
|
| 115 |
+
|
| 116 |
except Exception as e:
|
| 117 |
return jsonify({"error": f"Speech recognition error: {str(e)}"}), 500
|
| 118 |
|