Created
October 13, 2024 03:34
-
-
Save ColeMurray/0da4a484fce5aa6aa198553b1a4bbe8f to your computer and use it in GitHub Desktop.
AI Chatbot Cost Calculator Using Deepgram and Twilio
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>AI Chatbot Cost Calculator</title> | |
<style> | |
body { | |
font-family: Arial, sans-serif; | |
line-height: 1.6; | |
margin: 0; | |
padding: 20px; | |
background-color: #f4f4f4; | |
} | |
.container { | |
max-width: 600px; | |
margin: auto; | |
background: #fff; | |
padding: 20px; | |
border-radius: 5px; | |
box-shadow: 0 0 10px rgba(0,0,0,0.1); | |
} | |
h1 { | |
color: #333; | |
text-align: center; | |
} | |
label { | |
display: block; | |
margin-bottom: 5px; | |
} | |
input[type="number"], select { | |
width: 100%; | |
padding: 8px; | |
margin-bottom: 10px; | |
border: 1px solid #ddd; | |
border-radius: 4px; | |
} | |
button { | |
display: block; | |
width: 100%; | |
padding: 10px; | |
background-color: #007bff; | |
color: #fff; | |
border: none; | |
border-radius: 4px; | |
cursor: pointer; | |
margin-bottom: 10px; | |
} | |
button:hover { | |
background-color: #0056b3; | |
} | |
#result { | |
margin-top: 20px; | |
padding: 10px; | |
background-color: #e9ecef; | |
border-radius: 4px; | |
} | |
</style> | |
</head> | |
<body> | |
<div class="container"> | |
<h1>AI Chatbot Cost Calculator</h1> | |
<form id="calculatorForm"> | |
<label for="preset">Select a preset or custom:</label> | |
<select id="preset"> | |
<option value="custom">Custom</option> | |
<option value="short">Short Conversation</option> | |
<option value="medium">Medium Conversation</option> | |
<option value="long">Long Conversation</option> | |
</select> | |
<label for="callDuration">Call Duration (minutes):</label> | |
<input type="number" id="callDuration" required min="0" step="0.1"> | |
<label for="speechToTextDuration">Speech-to-Text Duration (minutes):</label> | |
<input type="number" id="speechToTextDuration" required min="0" step="0.1"> | |
<label for="textToSpeechChars">Text-to-Speech Characters:</label> | |
<input type="number" id="textToSpeechChars" required min="0"> | |
<button type="submit">Calculate Cost</button> | |
</form> | |
<div id="result"></div> | |
</div> | |
<script> | |
const presets = { | |
short: { callDuration: 3, speechToTextDuration: 2.5, textToSpeechChars: 500 }, | |
medium: { callDuration: 7, speechToTextDuration: 6, textToSpeechChars: 1200 }, | |
long: { callDuration: 15, speechToTextDuration: 13, textToSpeechChars: 2500 } | |
}; | |
document.getElementById('preset').addEventListener('change', function() { | |
const selectedPreset = this.value; | |
if (selectedPreset !== 'custom') { | |
const preset = presets[selectedPreset]; | |
document.getElementById('callDuration').value = preset.callDuration; | |
document.getElementById('speechToTextDuration').value = preset.speechToTextDuration; | |
document.getElementById('textToSpeechChars').value = preset.textToSpeechChars; | |
} | |
}); | |
document.getElementById('calculatorForm').addEventListener('submit', function(e) { | |
e.preventDefault(); | |
const callDuration = parseFloat(document.getElementById('callDuration').value); | |
const speechToTextDuration = parseFloat(document.getElementById('speechToTextDuration').value); | |
const textToSpeechChars = parseInt(document.getElementById('textToSpeechChars').value); | |
const speechToTextCost = speechToTextDuration * 0.0059; | |
const textToSpeechCost = (textToSpeechChars / 1000) * 0.0150; | |
const receiveCallsCost = callDuration * 0.0085; | |
const totalCost = speechToTextCost + textToSpeechCost + receiveCallsCost; | |
const resultHtml = ` | |
<h3>Cost Breakdown:</h3> | |
<p>Speech-to-Text Cost: $${speechToTextCost.toFixed(4)}</p> | |
<p>Text-to-Speech Cost: $${textToSpeechCost.toFixed(4)}</p> | |
<p>Receive Calls Cost: $${receiveCallsCost.toFixed(4)}</p> | |
<h4>Total Cost: $${totalCost.toFixed(4)}</h4> | |
`; | |
document.getElementById('result').innerHTML = resultHtml; | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment