Spaces:
Running
Running
File size: 58,642 Bytes
03e2aca 53a985d 03e2aca 53a985d 03e2aca 53a985d 03e2aca 53a985d 03e2aca 53a985d 03e2aca 53a985d 03e2aca 53a985d 03e2aca 53a985d 03e2aca 53a985d 03e2aca 53a985d 03e2aca 53a985d 03e2aca 53a985d 03e2aca 53a985d 03e2aca 26b46c4 53a985d 26b46c4 53a985d 26b46c4 53a985d 26b46c4 53a985d 26b46c4 53a985d 26b46c4 03e2aca 53a985d 26b46c4 53a985d 03e2aca 53a985d 03e2aca 53a985d 03e2aca 53a985d 03e2aca 53a985d 03e2aca 53a985d 03e2aca 53a985d 03e2aca 53a985d 03e2aca 26b46c4 03e2aca 53a985d 03e2aca 26b46c4 53a985d 03e2aca 53a985d 03e2aca 26b46c4 03e2aca 26b46c4 53a985d 26b46c4 53a985d 26b46c4 53a985d 26b46c4 53a985d 26b46c4 53a985d 26b46c4 53a985d 26b46c4 53a985d 26b46c4 53a985d 26b46c4 53a985d 26b46c4 53a985d 26b46c4 53a985d 03e2aca 26b46c4 03e2aca 26b46c4 03e2aca 26b46c4 03e2aca 53a985d 03e2aca 53a985d 03e2aca 53a985d 03e2aca 53a985d 03e2aca 53a985d 03e2aca 53a985d 03e2aca 53a985d 03e2aca 53a985d 03e2aca |
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 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Audio Studio Pro | YouTube-Style Recorder</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
:root {
--yt-red: #ff0000;
--yt-dark: #0f0f0f;
--yt-gray: #272727;
--yt-light-gray: #3f3f3f;
}
.waveform {
background: linear-gradient(90deg, #ff0000 0%, #cc0000 50%, #990000 100%);
height: 100px;
border-radius: 0.75rem;
position: relative;
overflow: hidden;
box-shadow: 0 4px 20px rgba(255, 0, 0, 0.3);
}
.waveform::after {
content: '';
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: linear-gradient(90deg,
rgba(255,255,255,0.15) 0%,
rgba(255,255,255,0.25) 50%,
rgba(255,255,255,0.15) 100%);
animation: wave 1.8s linear infinite;
transform: translateX(-100%);
}
@keyframes wave {
100% {
transform: translateX(100%);
}
}
.recording-animation {
animation: youtube-pulse 1.2s infinite;
}
@keyframes youtube-pulse {
0% {
box-shadow: 0 0 0 0 rgba(255, 0, 0, 0.8);
transform: scale(1);
}
50% {
transform: scale(1.05);
}
100% {
box-shadow: 0 0 0 15px rgba(255, 0, 0, 0);
transform: scale(1);
}
}
.format-option:hover {
transform: translateY(-5px);
box-shadow: 0 15px 30px rgba(255, 0, 0, 0.3);
background: var(--yt-gray) !important;
}
.format-option {
transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
border: 1px solid var(--yt-light-gray);
}
.device-option:hover {
background-color: var(--yt-gray) !important;
}
.device-option {
transition: all 0.3s ease;
}
.visualizer {
width: 100%;
height: 100px;
background: var(--yt-dark);
border-radius: 0.75rem;
position: relative;
overflow: hidden;
box-shadow: inset 0 2px 10px rgba(0,0,0,0.5);
}
.bar {
position: absolute;
bottom: 0;
width: 6px;
background: linear-gradient(to top, #ff0000, #cc0000);
border-radius: 3px 3px 0 0;
transition: height 0.08s ease;
}
.youtube-nav {
background: var(--yt-dark);
border-bottom: 1px solid var(--yt-light-gray);
}
.youtube-sidebar {
background: var(--yt-dark);
border-right: 1px solid var(--yt-light-gray);
}
.youtube-card {
background: var(--yt-gray);
border-radius: 1rem;
border: 1px solid var(--yt-light-gray);
box-shadow: 0 4px 25px rgba(0,0,0,0.4);
transition: all 0.3s ease;
}
.youtube-card:hover {
transform: translateY(-3px);
box-shadow: 0 8px 35px rgba(255, 0, 0, 0.2);
}
.gradient-text {
background: linear-gradient(135deg, #ff0000, #cc0000);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
}
.live-indicator {
background: var(--yt-red);
color: white;
padding: 2px 8px;
border-radius: 4px;
font-size: 0.75rem;
font-weight: bold;
animation: live-pulse 2s infinite;
}
@keyframes live-pulse {
0%, 100% { opacity: 1; }
50% { opacity: 0.7; }
}
.yt-button {
background: var(--yt-gray);
border: 1px solid var(--yt-light-gray);
transition: all 0.3s ease;
}
.yt-button:hover {
background: var(--yt-light-gray);
}
.yt-button-primary {
background: var(--yt-red);
border: 1px solid var(--yt-red);
}
.yt-button-primary:hover {
background: #cc0000;
border-color: #cc0000;
}
.progress-bar {
height: 4px;
background: var(--yt-light-gray);
border-radius: 2px;
overflow: hidden;
}
.progress-fill {
height: 100%;
background: var(--yt-red);
border-radius: 2px;
transition: width 0.1s linear;
}
.recording-item {
background: var(--yt-gray);
border: 1px solid var(--yt-light-gray);
border-radius: 0.75rem;
transition: all 0.3s ease;
}
.recording-item:hover {
background: #2a2a2a;
border-color: #4a4a4a;
}
.sidebar-item {
transition: all 0.2s ease;
}
.sidebar-item:hover {
background: var(--yt-light-gray);
}
</style>
</head>
<body class="bg-[#0f0f0f] min-h-screen text-white">
<!-- YouTube-style Navigation -->
<nav class="youtube-nav sticky top-0 z-50">
<div class="container mx-auto px-4 py-3">
<div class="flex items-center justify-between">
<div class="flex items-center gap-6">
<div class="flex items-center gap-2">
<i class="fas fa-bars text-xl cursor-pointer"></i>
<div class="flex items-center gap-2">
<i class="fab fa-youtube text-2xl text-red-500"></i>
<span class="text-xl font-bold">Audio Studio Pro</span>
</div>
</div>
</div>
<div class="flex-1 max-w-2xl mx-8">
<div class="relative">
<input type="text" placeholder="Search recordings..." class="w-full bg-[#121212] border border-[#303030] rounded-full py-2 px-4 text-sm focus:outline-none focus:border-[#3ea6ff] transition-all">
<i class="fas fa-search absolute right-3 top-2.5 text-gray-400"></i>
</div>
</div>
<div class="flex items-center gap-4">
<div class="flex items-center gap-2">
<span class="live-indicator flex items-center gap-1">
<i class="fas fa-circle text-xs"></i>
LIVE
</span>
</div>
</div>
</div>
</div>
</div>
</nav>
<div class="flex">
<!-- YouTube-style Sidebar -->
<div class="youtube-sidebar w-64 min-h-screen hidden md:block">
<div class="p-4 space-y-2">
<div class="sidebar-item p-3 rounded-lg bg-[#272727] cursor-pointer">
<div class="flex items-center gap-3">
<i class="fas fa-home text-red-500"></i>
<span>Home</span>
</div>
<div class="sidebar-item p-3 rounded-lg cursor-pointer">
<div class="flex items-center gap-3">
<i class="fas fa-fire text-red-500"></i>
<span>Trending</span>
</div>
<div class="sidebar-item p-3 rounded-lg cursor-pointer">
<div class="flex items-center gap-3">
<i class="fas fa-microphone text-red-500"></i>
<span>Recordings</span>
</div>
<div class="sidebar-item p-3 rounded-lg cursor-pointer">
<div class="flex items-center gap-3">
<i class="fas fa-music text-red-500"></i>
<span>Music</span>
</div>
<div class="sidebar-item p-3 rounded-lg cursor-pointer">
<div class="flex items-center gap-3">
<i class="fas fa-cog text-red-500"></i>
<span>Settings</span>
</div>
</div>
</div>
<!-- Main Content -->
<div class="flex-1">
<div class="container mx-auto px-4 py-6">
<div class="max-w-5xl mx-auto">
<!-- Header Section -->
<div class="flex items-center justify-between mb-8">
<div>
<h1 class="text-3xl font-bold gradient-text mb-2">Audio Studio Pro</h1>
<p class="text-gray-400">Professional recording studio with YouTube-inspired interface</p>
</div>
<div class="flex items-center gap-3">
<div class="flex items-center gap-2 text-sm text-gray-400">
<i class="fas fa-users"></i>
<span>1.2K active</span>
</div>
</div>
<!-- Main Recording Card -->
<div class="youtube-card overflow-hidden mb-8">
<div class="p-6">
<!-- Live Status Header -->
<div class="flex items-center justify-between mb-6">
<div class="flex items-center gap-3">
<div class="w-3 h-3 bg-red-500 rounded-full animate-pulse"></div>
<span class="text-red-500 font-semibold">RECORDING STUDIO</div>
<div class="live-indicator flex items-center gap-2">
<i class="fas fa-circle text-xs"></i>
LIVE INPUT
</div>
</div>
<!-- Device Selection Section -->
<div class="mb-6">
<div class="flex items-center justify-between mb-3">
<h3 class="text-lg font-semibold text-white">Audio Input Devices</h3>
<button id="refreshDevices" class="yt-button px-3 py-1 rounded-lg text-sm">
<i class="fas fa-sync-alt mr-1"></i>
Refresh
</button>
</div>
<div class="flex flex-col sm:flex-row gap-4 mb-4">
<div class="flex-1">
<label for="audioSource" class="block text-sm font-medium text-gray-300 mb-1">Audio Input</label>
<select id="audioSource" class="w-full bg-[#272727] border border-[#3f3f3f] rounded-lg py-2 px-3 text-white focus:outline-none focus:border-[#ff0000] transition-all">
<option value="">Default Device</option>
</select>
</div>
<div class="flex-1">
<label for="audioQuality" class="block text-sm font-medium text-gray-300 mb-1">Quality Preset</label>
<select id="audioQuality" class="w-full bg-[#272727] border border-[#3f3f3f] rounded-lg py-2 px-3 text-white focus:outline-none focus:border-[#ff0000] transition-all">
<option value="high">Studio (24-bit/96kHz)</option>
<option value="medium" selected>Professional (16-bit/48kHz)</option>
<option value="low">Podcast (16-bit/44.1kHz)</option>
</select>
</div>
</div>
<!-- Advanced Settings -->
<div class="mb-4">
<div class="flex items-center justify-between mb-2">
<h4 class="text-sm font-medium text-gray-300">Advanced Settings</h4>
<button id="toggleAdvanced" class="yt-button px-3 py-1 rounded-lg text-sm">
<i class="fas fa-sliders-h mr-1"></i>
Show Advanced
</button>
</div>
<div id="advancedSettings" class="hidden grid grid-cols-2 gap-4 mb-4">
<div>
<label for="noiseReduction" class="block text-sm text-gray-400 mb-1">Noise Reduction</label>
<select id="noiseReduction" class="w-full bg-[#272727] border border-[#3f3f3f] rounded-lg py-2 px-3 text-white focus:outline-none focus:border-[#ff0000] transition-all">
<option value="high">High</option>
<option value="medium" selected>Medium</option>
<option value="low">Low</option>
<option value="off">Off</option>
</select>
</div>
<div>
<label for="autoGain" class="block text-sm text-gray-400 mb-1">Auto Gain</label>
<select id="autoGain" class="w-full bg-[#272727] border border-[#3f3f3f] rounded-lg py-2 px-3 text-white focus:outline-none focus:border-[#ff0000] transition-all">
<option value="on" selected>On</option>
<option value="off">Off</option>
</select>
</div>
</div>
<div class="visualizer mb-4" id="visualizer">
<!-- Audio bars will be inserted here by JavaScript -->
</div>
<div class="flex items-center justify-between text-sm">
<div id="deviceStatus" class="text-gray-400">
<i class="fas fa-microphone-slash mr-1"></i> No device selected
</div>
<div class="text-gray-400">
<i class="fas fa-database mr-1"></i>
<span id="fileSize">0 MB</span>
</div>
</div>
</div>
<!-- Waveform Display -->
<div class="waveform mb-6" id="waveform"></div>
<!-- Control Buttons -->
<div class="flex flex-col sm:flex-row justify-center items-center gap-4 mb-6">
<button id="recordBtn" class="yt-button-primary font-bold py-3 px-8 rounded-full flex items-center gap-2 transition-all">
<i class="fas fa-record-vinyl"></i> Start Recording
</button>
<button id="stopBtn" disabled class="yt-button font-bold py-3 px-8 rounded-full flex items-center gap-2 transition-all">
<i class="fas fa-stop"></i> Stop
</button>
<button id="playBtn" disabled class="yt-button font-bold py-3 px-8 rounded-full flex items-center gap-2 transition-all">
<i class="fas fa-play"></i> Preview
</button>
</div>
<!-- Progress and Timer -->
<div class="mb-4">
<div class="progress-bar mb-2">
<div id="progressFill" class="progress-fill" style="width: 0%"></div>
<div class="flex justify-between items-center">
<span id="timer" class="text-gray-400">00:00</span>
<span class="text-gray-400">
<i class="fas fa-volume-up mr-1"></i>
<span id="volumeLevel">50%</span>
</div>
</div>
</div>
</div>
<!-- Download Section -->
<div class="bg-[#1f1f1f] p-6 border-t border-[#3f3f3f]">
<h3 class="text-lg font-semibold text-white mb-4">Export & Download</h3>
<div class="grid grid-cols-2 sm:grid-cols-4 gap-4 mb-6">
<div class="format-option bg-[#272727] p-4 rounded-lg text-center cursor-pointer" data-format="wav">
<i class="fas fa-file-waveform text-3xl text-red-500 mb-2"></i>
<p class="font-medium">WAV</p>
<p class="text-sm text-gray-400">Lossless Quality</p>
</div>
<div class="format-option bg-[#272727] p-4 rounded-lg text-center cursor-pointer" data-format="mp3">
<i class="fas fa-file-audio text-3xl text-red-400 mb-2"></i>
<p class="font-medium">MP3</p>
<p class="text-sm text-gray-400">Universal Format</p>
</div>
<div class="format-option bg-[#272727] p-4 rounded-lg text-center cursor-pointer" data-format="ogg">
<i class="fas fa-file-audio text-3xl text-red-300 mb-2"></i>
<p class="font-medium">OGG</p>
<p class="text-sm text-gray-400">Web Streaming</p>
</div>
<div class="format-option bg-[#272727] p-4 rounded-lg text-center cursor-pointer" data-format="aac">
<i class="fas fa-file-audio text-3xl text-red-200 mb-2"></i>
<p class="font-medium">AAC</p>
<p class="text-sm text-gray-400">Mobile Devices</p>
</div>
</div>
<div class="flex gap-4">
<button id="downloadBtn" disabled class="flex-1 yt-button-primary font-bold py-3 px-4 rounded-lg flex items-center justify-center gap-2 transition-all">
<i class="fas fa-download"></i> Download Selected Format
</button>
<button id="shareBtn" disabled class="yt-button px-4 py-3 rounded-lg flex items-center gap-2">
<i class="fas fa-share-alt"></i>
</button>
</div>
</div>
</div>
<!-- Recording History Section -->
<div class="youtube-card mt-8">
<div class="p-6">
<div class="flex items-center justify-between mb-4">
<h3 class="text-lg font-semibold text-white">Recording Library</h3>
<div class="flex items-center gap-2 text-sm text-gray-400">
<i class="fas fa-history"></i>
<span>Recent Recordings</span>
</div>
</div>
<div id="recordingsList" class="space-y-3">
<div class="text-center text-gray-500 py-8">
<i class="fas fa-microphone-slash text-3xl mb-2"></i>
<p>No recordings in your library</p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
// Audio recording variables
let mediaRecorder;
let audioChunks = [];
let audioBlob;
let audioUrl;
let audioElement;
let timerInterval;
let seconds = 0;
let audioContext;
let analyser;
let microphone;
let dataArray;
let animationId;
let currentStream;
// DOM elements
const recordBtn = document.getElementById('recordBtn');
const stopBtn = document.getElementById('stopBtn');
const playBtn = document.getElementById('playBtn');
const downloadBtn = document.getElementById('downloadBtn');
const shareBtn = document.getElementById('shareBtn');
const timer = document.getElementById('timer');
const recordingsList = document.getElementById('recordingsList');
const formatOptions = document.querySelectorAll('.format-option');
const audioSourceSelect = document.getElementById('audioSource');
const audioQualitySelect = document.getElementById('audioQuality');
const visualizer = document.getElementById('visualizer');
const deviceStatus = document.getElementById('deviceStatus');
const refreshDevicesBtn = document.getElementById('refreshDevices');
const toggleAdvancedBtn = document.getElementById('toggleAdvanced');
const advancedSettings = document.getElementById('advancedSettings');
const progressFill = document.getElementById('progressFill');
const fileSize = document.getElementById('fileSize');
const volumeLevel = document.getElementById('volumeLevel');
const mobileRecordBtn = document.getElementById('mobileRecordBtn');
let selectedFormat = 'wav'; // Default format
let isAdvancedVisible = false;
// Initialize features
function initFeatures() {
// Toggle advanced settings
toggleAdvancedBtn.addEventListener('click', function() {
isAdvancedVisible = !isAdvancedVisible;
if (isAdvancedVisible) {
advancedSettings.classList.remove('hidden');
this.innerHTML = '<i class="fas fa-times mr-1"></i> Hide Advanced';
} else {
advancedSettings.classList.add('hidden');
this.innerHTML = '<i class="fas fa-sliders-h mr-1"></i> Show Advanced';
}
});
// Refresh devices
refreshDevicesBtn.addEventListener('click', function() {
this.classList.add('animate-spin');
getAudioDevices().then(success => {
setTimeout(() => {
this.classList.remove('animate-spin');
// Trigger device selection update
if (audioSourceSelect.value) {
audioSourceSelect.dispatchEvent(new Event('change'));
}, 500);
});
// Mobile record button
if (mobileRecordBtn) {
mobileRecordBtn.addEventListener('click', function() {
recordBtn.click();
});
}
// Volume control simulation
let volume = 50;
setInterval(() => {
if (audioElement && !audioElement.paused) {
volume = Math.min(100, Math.max(0, volume + (Math.random() * 4 - 2));
volumeLevel.textContent = `${Math.round(volume)}%`;
}
}, 1000);
}
// Create audio bars for visualizer
const barCount = 40;
for (let i = 0; i < barCount; i++) {
const bar = document.createElement('div');
bar.className = 'bar';
bar.style.left = `${i * (100 / barCount)}%`;
bar.style.height = '0%';
visualizer.appendChild(bar);
}
const bars = document.querySelectorAll('.bar');
// Format selection
formatOptions.forEach(option => {
option.addEventListener('click', function() {
formatOptions.forEach(opt => opt.classList.remove('ring-2', 'ring-red-500'));
this.classList.add('ring-2', 'ring-red-500');
selectedFormat = this.dataset.format;
});
});
// Set first format as selected by default
formatOptions[0].classList.add('ring-2', 'ring-red-500');
// Initialize features
initFeatures();
let selectedFormat = 'wav'; // Default format
// Create audio bars for visualizer
const barCount = 40;
for (let i = 0; i < barCount; i++) {
const bar = document.createElement('div');
bar.className = 'bar';
bar.style.left = `${i * (100 / barCount)}%`;
bar.style.height = '0%';
visualizer.appendChild(bar);
}
const bars = document.querySelectorAll('.bar');
// Format selection
formatOptions.forEach(option => {
option.addEventListener('click', function() {
formatOptions.forEach(opt => opt.classList.remove('ring-2', 'ring-indigo-500'));
this.classList.add('ring-2', 'ring-indigo-500');
selectedFormat = this.dataset.format;
});
});
// Set first format as selected by default
formatOptions[0].classList.add('ring-2', 'ring-indigo-500');
// Get available audio devices
async function getAudioDevices() {
try {
// First get permission by accessing media
const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
stopStream(stream); // We don't need this stream, just needed for permission
// Now enumerate devices
const devices = await navigator.mediaDevices.enumerateDevices();
const audioInputs = devices.filter(device => device.kind === 'audioinput');
// Clear existing options
audioSourceSelect.innerHTML = '<option value="">Default Device</option>';
// Add each audio input device as an option
audioInputs.forEach(device => {
const option = document.createElement('option');
option.value = device.deviceId;
option.text = device.label || `Microphone ${audioSourceSelect.length}`;
audioSourceSelect.appendChild(option);
});
return true;
} catch (error) {
console.error('Error getting audio devices:', error);
deviceStatus.innerHTML = '<i class="fas fa-exclamation-triangle mr-1"></i> Could not access microphone devices';
return false;
}
}
// Simulate file size calculation
function updateFileSize(duration) {
const baseSize = duration * 0.1; // MB per minute
fileSize.textContent = `${baseSize.toFixed(1)} MB estimated';
}
// Stop a media stream
function stopStream(stream) {
if (stream) {
stream.getTracks().forEach(track => track.stop());
}
}
// Visualize audio input
function visualizeAudio(stream) {
// Create audio context if it doesn't exist
if (!audioContext) {
audioContext = new (window.AudioContext || window.webkitAudioContext)();
}
// Create analyser node
analyser = audioContext.createAnalyser();
analyser.fftSize = 256;
// Create microphone source
microphone = audioContext.createMediaStreamSource(stream);
microphone.connect(analyser);
// Create data array for analysis
const bufferLength = analyser.frequencyBinCount;
dataArray = new Uint8Array(bufferLength);
// Start animation loop
function animate() {
animationId = requestAnimationFrame(animate);
analyser.getByteFrequencyData(dataArray);
// Update bars
for (let i = 0; i < bars.length; i++) {
// Scale the index to cover the full frequency range
const scaledIndex = Math.floor(i * (bufferLength / bars.length));
const value = dataArray[scaledIndex];
const height = value / 2.55; // Convert 0-255 to 0-100
bars[i].style.height = `${height}%`;
bars[i].style.backgroundColor = `hsl(${200 + (height * 1.5)}, 100%, 50%)`;
}
}
// Start animation
animate();
// Update device status
deviceStatus.innerHTML = `<i class="fas fa-microphone mr-1"></i> ${audioSourceSelect.options[audioSourceSelect.selectedIndex].text}`;
}
// Stop visualization
function stopVisualization() {
if (animationId) {
cancelAnimationFrame(animationId);
animationId = null;
}
// Reset bars
bars.forEach(bar => {
bar.style.height = '0%';
bar.style.backgroundColor = '#3b82f6';
});
// Update device status
deviceStatus.innerHTML = '<i class="fas fa-microphone-slash mr-1"></i> No active input';
}
// Get audio constraints based on selected quality
function getAudioConstraints() {
const deviceId = audioSourceSelect.value;
const quality = audioQualitySelect.value;
let constraints = {
audio: {
deviceId: deviceId ? { exact: deviceId } : undefined,
echoCancellation: true,
noiseSuppression: true,
autoGainControl: true
}
};
// Adjust constraints based on quality
if (quality === 'high') {
constraints.audio.sampleRate = 96000;
constraints.audio.channelCount = 2;
constraints.audio.sampleSize = 24;
constraints.audio.bitrate = 320000;
} else if (quality === 'medium') {
constraints.audio.sampleRate = 48000;
constraints.audio.channelCount = 1;
constraints.audio.sampleSize = 16;
constraints.audio.bitrate = 192000;
} else { // low
constraints.audio.sampleRate = 44100;
constraints.audio.channelCount = 1;
constraints.audio.sampleSize = 16;
constraints.audio.bitrate = 128000;
}
return constraints;
}
// Enhanced visualization with YouTube colors
function visualizeAudio(stream) {
// Create audio context if it doesn't exist
if (!audioContext) {
audioContext = new (window.AudioContext || window.webkitAudioContext)();
}
// Create analyser node
analyser = audioContext.createAnalyser();
analyser.fftSize = 512;
// Create microphone source
microphone = audioContext.createMediaStreamSource(stream);
microphone.connect(analyser);
// Create data array for analysis
const bufferLength = analyser.frequencyBinCount;
dataArray = new Uint8Array(bufferLength);
// Start animation loop
function animate() {
animationId = requestAnimationFrame(animate);
analyser.getByteFrequencyData(dataArray);
// Update bars with YouTube red gradient
for (let i = 0; i < bars.length; i++) {
// Scale the index to cover the full frequency range
const scaledIndex = Math.floor(i * (bufferLength / bars.length));
const value = dataArray[scaledIndex];
const height = value / 2.55; // Convert 0-255 to 0-100
bars[i].style.height = `${height}%`;
// Dynamic color based on amplitude
const hue = 0; // Red
const saturation = 100;
const lightness = 40 + (height * 0.3);
bars[i].style.background = `linear-gradient(to top, hsl(${hue}, ${saturation}%, ${lightness}%), hsl(${hue}, ${saturation}%, ${Math.max(20, lightness - 20)}%)`;
}
}
// Start animation
animate();
// Update device status with YouTube style
deviceStatus.innerHTML = `<i class="fas fa-microphone mr-1"></i> <span class="text-red-400">${audioSourceSelect.options[audioSourceSelect.selectedIndex].text}</span>`;
}
// Initialize device selection
getAudioDevices().then(success => {
if (success) {
// When device selection changes, update the visualization
audioSourceSelect.addEventListener('change', async function() {
// Stop any existing visualization
stopVisualization();
if (currentStream) {
stopStream(currentStream);
}
// If a device is selected, start visualization
if (this.value) {
try {
const constraints = getAudioConstraints();
currentStream = await navigator.mediaDevices.getUserMedia(constraints);
visualizeAudio(currentStream);
updateFileSize(0);
} catch (error) {
console.error('Error accessing selected device:', error);
deviceStatus.innerHTML = '<i class="fas fa-exclamation-triangle mr-1"></i> Could not access selected device';
}
}
});
// Also update when quality changes
audioQualitySelect.addEventListener('change', function() {
if (audioSourceSelect.value) {
// Trigger change event to restart with new quality
audioSourceSelect.dispatchEvent(new Event('change'));
}
});
}
});
// Enhanced recording with progress tracking
recordBtn.addEventListener('click', async function() {
try {
const constraints = getAudioConstraints();
const stream = await navigator.mediaDevices.getUserMedia(constraints);
currentStream = stream;
// Stop visualization if it's running
stopVisualization();
mediaRecorder = new MediaRecorder(stream);
audioChunks = [];
mediaRecorder.ondataavailable = function(event) {
audioChunks.push(event.data);
};
mediaRecorder.onstop = function() {
audioBlob = new Blob(audioChunks, { type: 'audio/wav' });
audioUrl = URL.createObjectURL(audioBlob);
// Create audio element for playback
audioElement = new Audio(audioUrl);
// Enable play, download, and share buttons
playBtn.disabled = false;
downloadBtn.disabled = false;
shareBtn.disabled = false;
// Add to recordings list
addRecordingToList(audioUrl);
// Restart visualization if a device was selected
if (audioSourceSelect.value) {
visualizeAudio(currentStream);
}
};
mediaRecorder.start(10); // Collect data every 10ms
// Start timer and progress
seconds = 0;
updateTimer();
updateProgress();
timerInterval = setInterval(() => {
seconds++;
updateTimer();
updateProgress();
updateFileSize(seconds / 60);
}, 1000);
// Update UI with YouTube styling
recordBtn.disabled = true;
recordBtn.classList.remove('yt-button-primary');
recordBtn.classList.add('bg-gray-600', 'cursor-not-allowed');
stopBtn.disabled = false;
stopBtn.classList.remove('yt-button');
stopBtn.classList.add('yt-button-primary');
// Add recording animation
recordBtn.classList.add('recording-animation');
// Update mobile button if exists
if (mobileRecordBtn) {
mobileRecordBtn.classList.add('recording-animation');
}
} catch (error) {
console.error('Error accessing microphone:', error);
alert('Could not access microphone. Please check permissions.');
}
});
// Enhanced stop recording
stopBtn.addEventListener('click', function() {
if (mediaRecorder && mediaRecorder.state !== 'inactive') {
mediaRecorder.stop();
// Stop all tracks in the stream
stopStream(currentStream);
// Clear timer and progress
clearInterval(timerInterval);
progressFill.style.width = '0%';
// Update UI
recordBtn.disabled = false;
recordBtn.classList.remove('bg-gray-600', 'cursor-not-allowed');
recordBtn.classList.add('yt-button-primary');
stopBtn.disabled = true;
stopBtn.classList.remove('yt-button-primary');
stopBtn.classList.add('yt-button');
// Remove recording animation
recordBtn.classList.remove('recording-animation');
// Update mobile button if exists
if (mobileRecordBtn) {
mobileRecordBtn.classList.remove('recording-animation');
}
}
});
// Enhanced play with progress tracking
playBtn.addEventListener('click', function() {
if (audioElement) {
if (audioElement.paused) {
audioElement.play();
playBtn.innerHTML = '<i class="fas fa-pause"></i> Pause';
// Update progress as audio plays
const updatePlayProgress = setInterval(() => {
if (audioElement.paused || audioElement.ended) {
clearInterval(updatePlayProgress);
playBtn.innerHTML = '<i class="fas fa-play"></i> Preview';
progressFill.style.width = '0%';
} else {
const progress = (audioElement.currentTime / audioElement.duration) * 100;
progressFill.style.width = `${progress}%`;
}, 100);
} else {
audioElement.pause();
playBtn.innerHTML = '<i class="fas fa-play"></i> Preview';
}
}
});
// Enhanced download
downloadBtn.addEventListener('click', function() {
if (audioBlob) {
const a = document.createElement('a');
a.style.display = 'none';
a.href = audioUrl;
a.download = `recording_${new Date().toISOString().slice(0, 19).replace(/[:T-]/g, '_')}.${selectedFormat}`;
document.body.appendChild(a);
a.click();
setTimeout(() => {
document.body.removeChild(a);
}, 100);
}
});
// Share functionality
shareBtn.addEventListener('click', function() {
if (audioBlob) {
if (navigator.share) {
navigator.share({
title: 'My Recording',
text: 'Check out this recording I made!',
files: [new File([audioBlob], `recording_${new Date().toISOString().slice(0, 19).replace(/[:T-]/g, '_')}.${selectedFormat}`
}).catch(console.error);
} else {
alert('Sharing not supported in this browser. Download the file instead.');
}
}
});
// Update timer display
function updateTimer() {
const minutes = Math.floor(seconds / 60);
const remainingSeconds = seconds % 60;
timer.textContent = `${minutes.toString().padStart(2, '0')}:${remainingSeconds.toString().padStart(2, '0')}`;
}
// Update progress bar
function updateProgress() {
const progress = (seconds / 300) * 100; // 5 minute max
progressFill.style.width = `${Math.min(100, progress)}%`;
}
// Request permission to use microphone
recordBtn.addEventListener('click', async function() {
try {
const constraints = getAudioConstraints();
const stream = await navigator.mediaDevices.getUserMedia(constraints);
currentStream = stream;
// Stop visualization if it's running
stopVisualization();
mediaRecorder = new MediaRecorder(stream);
audioChunks = [];
mediaRecorder.ondataavailable = function(event) {
audioChunks.push(event.data);
};
mediaRecorder.onstop = function() {
audioBlob = new Blob(audioChunks, { type: 'audio/wav' });
audioUrl = URL.createObjectURL(audioBlob);
// Create audio element for playback
audioElement = new Audio(audioUrl);
// Enable play and download buttons
playBtn.disabled = false;
downloadBtn.disabled = false;
// Add to recordings list
addRecordingToList(audioUrl);
// Restart visualization if a device was selected
if (audioSourceSelect.value) {
visualizeAudio(currentStream);
}
};
mediaRecorder.start(10); // Collect data every 10ms
// Start timer
seconds = 0;
updateTimer();
timerInterval = setInterval(updateTimer, 1000);
// Update UI
recordBtn.disabled = true;
recordBtn.classList.remove('bg-red-500', 'hover:bg-red-600');
recordBtn.classList.add('bg-gray-300', 'text-gray-600');
stopBtn.disabled = false;
stopBtn.classList.remove('bg-gray-300', 'text-gray-600');
stopBtn.classList.add('bg-gray-800', 'hover:bg-gray-900', 'text-white');
// Add recording animation
recordBtn.classList.add('recording-animation');
} catch (error) {
console.error('Error accessing microphone:', error);
alert('Could not access microphone. Please check permissions.');
}
});
// Stop recording
stopBtn.addEventListener('click', function() {
if (mediaRecorder && mediaRecorder.state !== 'inactive') {
mediaRecorder.stop();
// Stop all tracks in the stream
stopStream(currentStream);
// Clear timer
clearInterval(timerInterval);
// Update UI
recordBtn.disabled = false;
recordBtn.classList.remove('bg-gray-300', 'text-gray-600');
recordBtn.classList.add('bg-red-500', 'hover:bg-red-600');
stopBtn.disabled = true;
stopBtn.classList.remove('bg-gray-800', 'hover:bg-gray-900', 'text-white');
stopBtn.classList.add('bg-gray-300', 'text-gray-600');
// Remove recording animation
recordBtn.classList.remove('recording-animation');
}
});
// Play recording
playBtn.addEventListener('click', function() {
if (audioElement) {
if (audioElement.paused) {
audioElement.play();
playBtn.innerHTML = '<i class="fas fa-pause"></i> Pause';
} else {
audioElement.pause();
playBtn.innerHTML = '<i class="fas fa-play"></i> Play';
}
}
});
// Download recording
downloadBtn.addEventListener('click', function() {
if (audioBlob) {
const a = document.createElement('a');
a.style.display = 'none';
a.href = audioUrl;
a.download = `recording_${new Date().toISOString().slice(0, 19).replace(/[:T-]/g, '_')}.${selectedFormat}`;
document.body.appendChild(a);
a.click();
setTimeout(() => {
document.body.removeChild(a);
window.URL.revokeObjectURL(audioUrl);
}, 100);
}
});
// Update timer display
function updateTimer() {
seconds++;
const minutes = Math.floor(seconds / 60);
const remainingSeconds = seconds % 60;
timer.textContent = `${minutes.toString().padStart(2, '0')}:${remainingSeconds.toString().padStart(2, '0')}`;
}
// Enhanced recording history with YouTube cards
function addRecordingToList(url) {
// Remove placeholder if it exists
if (recordingsList.querySelector('.text-center')) {
recordingsList.innerHTML = '';
}
const recordingItem = document.createElement('div');
recordingItem.className = 'recording-item p-4 flex items-center justify-between';
recordingItem.innerHTML = `
<div class="flex items-center gap-4">
<div class="w-12 h-12 bg-red-500 rounded-lg flex items-center justify-center">
<i class="fas fa-wave-square"></i>
</div>
<div class="flex-1">
<p class="font-medium text-white">Recording ${recordingsList.children.length + 1}</p>
<p class="text-sm text-gray-400">${new Date().toLocaleString()}</p>
<p class="text-xs text-gray-500">${audioSourceSelect.options[audioSourceSelect.selectedIndex].text}</p>
</div>
</div>
<div class="flex gap-2">
<button class="play-history-btn yt-button p-2 rounded-lg">
<i class="fas fa-play text-xs"></i>
</button>
<button class="download-history-btn yt-button p-2 rounded-lg">
<i class="fas fa-download text-xs"></i>
</button>
<button class="share-history-btn yt-button p-2 rounded-lg">
<i class="fas fa-share-alt text-xs"></i>
</button>
</div>
</div>
`;
recordingsList.prepend(recordingItem);
// Add event listeners to the new buttons
const playBtn = recordingItem.querySelector('.play-history-btn');
const downloadBtn = recordingItem.querySelector('.download-history-btn');
const shareBtn = recordingItem.querySelector('.share-history-btn');
const audio = new Audio(url);
playBtn.addEventListener('click', function() {
if (audio.paused) {
// Stop all other audio elements first
document.querySelectorAll('audio').forEach(a => {
if (a !== audio) a.pause();
});
audio.play();
playBtn.innerHTML = '<i class="fas fa-pause text-xs"></i>';
} else {
audio.pause();
playBtn.innerHTML = '<i class="fas fa-play text-xs"></i>';
}
});
downloadBtn.addEventListener('click', function() {
const a = document.createElement('a');
a.style.display = 'none';
a.href = url;
a.download = `recording_${new Date().toISOString().slice(0, 19).replace(/[:T-]/g, '_')}.${selectedFormat}`;
document.body.appendChild(a);
a.click();
setTimeout(() => {
document.body.removeChild(a);
}, 100);
});
shareBtn.addEventListener('click', function() {
if (navigator.share) {
navigator.share({
title: `Recording ${recordingsList.children.length}`,
text: 'Check out this recording I made with Audio Studio Pro!',
});
}
});
// Reset play button when audio ends
audio.addEventListener('ended', function() {
playBtn.innerHTML = '<i class="fas fa-play text-xs"></i>';
});
}
});
</script>
<!-- Footer with credits -->
<div class="mt-12 border-t border-[#3f3f3f] pt-6">
<div class="flex flex-col sm:flex-row justify-between items-center text-sm text-gray-400">
<div class="flex items-center gap-4">
<span>Powered by</span>
<a href="https://huggingface.co/terastudio" target="_blank" class="hover:text-white transition-colors">
<i class="fas fa-brain mr-1"></i>
TeraStudio AI
</a>
</div>
<div class="flex items-center gap-4 mt-4 sm:mt-0">
<span>Made with</span>
<a href="https://enzostvs-deepsite.hf.space" target="_blank" class="hover:text-white transition-colors">
<img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);">
DeepSite
</a>
<span>•</span>
<a href="https://enzostvs-deepsite.hf.space?remix=NeoPy/audio-recorder" target="_blank" class="hover:text-white transition-colors">
🧬 Remix Project
</a>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Floating Action Button for Mobile -->
<div class="fixed bottom-6 right-6 md:hidden">
<button id="mobileRecordBtn" class="yt-button-primary w-14 h-14 rounded-full flex items-center justify-center shadow-lg">
<i class="fas fa-microphone"></i>
</button>
</div>
</body>
</html> |