
    }i&6                        d Z ddlZddlZddlZddlZddlmZ ddlZddlm	Z	 dZ
dZdZ ed      Zed	z  d
z  Zed	z  dz  dz  ZdZdZdZdZd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z e!dk(  r		  e         yy# e"$ r  e#d        ejH                  d       Y ye%$ r<Z& e#d e&        ddl'Z' e'jP                           ejH                  d!       Y dZ&[&ydZ&[&ww xY w)"aU  
AIVA Demo Recording Script
Generates hero page voiceover using Telnyx TTS API with AIVA's voice (eucalyptus)

Usage:
    python record_demo.py

Output:
    /mnt/e/genesis-system/RECEPTIONISTAI/assets/audio/demo.opus (primary)
    /mnt/e/genesis-system/RECEPTIONISTAI/assets/audio/demo.mp3 (fallback)

Author: Genesis AI
Created: 2026-02-15
    N)Path)Document:KEY019BE7A3A2D749FCA8681CFF8448A7F0_vTMM1n77CtQxLDT2ra3P1zz(https://api.telnyx.com/v2/text-to-speech
eucalyptusz/mnt/e/genesis-systemRECEPTIONISTAIz.Receptionist AI Pre-Recording Demo Script.docxassetsaudioi"V  32k48ka<  Hello, I'm Maya from Receptionist AI, and I'm about to become your new receptionist. But here's something you should know upfront - I'm not a real person. I'm an AI voice agent, though I bet I sound pretty convincing, right?

Let me show you what I actually do. Every single day, I answer your business phones around the clock - morning calls, evening inquiries, even 3am emergencies. I never take a sick day, never go on holiday, and I'm never too busy to pick up.

When someone rings asking about your services, I've got the answers. Pricing questions? Handled. Booking an appointment? Done and confirmed. Want to know your opening hours or location? I've got it covered.

But here's where it gets interesting: after every conversation, I immediately text and email them a summary of what we discussed. Confirmation details, next steps, everything they need. No delays, no forgetting to follow up.

I can do something else that's pretty powerful - I'll work through your contact list and reconnect with people who showed interest months ago but never booked. Old quotes, abandoned inquiries, dead leads - I bring them back to life.

Want proof this works? I recently handled one business's phones for a day and secured 30 confirmed bookings before dinner time. Appointments they would've completely missed otherwise.

And it gets even better. I learn from every single interaction. Each conversation makes me smarter and more capable at understanding your customers and getting them to say yes.

Ready to see how I'd sound talking about YOUR specific business? Enter your website address below and I'll call you in the next 30 seconds with a personalized demonstration. You'll hear me discuss your actual services, your location, everything - like I'm already working for you.

Go ahead, enter your details. Let's see what I can do for your business.c                  V    t         j                  dd       t        dt                 y)z,Create output directory if it doesn't exist.T)parentsexist_oku   ✅ Output directory ready: N)
OUTPUT_DIRmkdirprint     ;/mnt/e/genesis-system/RECEPTIONISTAI/scripts/record_demo.pysetup_output_directoryr   F   s%    TD1	(
56r   c                     	 t        dt                t        t        t                    } | j                  D cg c]7  }|j
                  j                         s|j
                  j                         9 }}t        |      dkD  rdj                  |dd       }ndj                  |      }t        dt        |       d       |S c c}w # t        $ r#}t        d|        t        d       Y d}~yd}~ww xY w)	zh
    Extract script text from the .docx file.
    Returns the script text or None if reading fails.
    u   📖 Reading script from:    z

Nu   ✅ Script loaded (z characters)u   ⚠️  Failed to read docx: z   Using fallback script text)
r   SCRIPT_DOCXr   str
paragraphstextstriplenjoin	Exception)docpr   script_textes        r   read_script_from_docxr$   L   s    
*;-89s;'( /2nnOaffllnO
O z?Q ++jn5K ++j1K#C$4#5\BC P  -aS12-.s/   8C CC6AC C 	C7C22C7c                     t        d       t        dt                t        dt        |        d       dt         dd}t        | dt        d	}	 t        j                  t        ||d
      }|j                  dk(  r=t        d       t        dt        |j                        dz  dd       |j                  S t        d|j                          t        d|j                          y# t        $ r}t        d|        Y d}~yd}~ww xY w)zg
    Call Telnyx TTS API to generate audio.
    Returns the audio data (bytes) or None on failure.
    u#   
🎙️  Calling Telnyx TTS API...z
   Voice: z   Text length: z characterszBearer zapplication/json)AuthorizationzContent-Typewav)voicer   audio_formatsample_rate<   )headersjsontimeout   u   ✅ TTS generation successfulz   Audio size:    .1fz KBu   ❌ TTS API error: z   Response: Nu   ❌ TTS request failed: )r   
VOICE_NAMEr   TELNYX_API_KEYSAMPLE_RATErequestspostTELNYX_TTS_URLstatus_codecontentr   r   )r   r,   payloadresponser#   s        r   call_telnyx_ttsr<   g   s   
 
02	Jzl
#$	SYK{
34 #>"23*G "	G==	
 3&13OC(8(8$9D$@#ESIJ###'(<(<'=>?M(--12 (,-s   A(C, ;0C, ,	D5DDc                     t         |z  }	 t        |d      5 }|j                  |        ddd       t        d|        |S # 1 sw Y   xY w# t        $ r}t        d| d|        Y d}~yd}~ww xY w)zSave audio data to a file.wbNu   ✅ Saved: u   ❌ Failed to save z: )r   openwriter   r   )
audio_datafilenamefilepathfr#   s        r   save_audio_filerE      s|    H$H(D! 	 QGGJ	 H:&'	  	   #H:Rs34s-   A AA A
A 	A1A,,A1c                    t        d| d       t        ddj                  |               	 t        j                  | ddd      }t        d| d       y# t        j                  $ r1}t        d	| d
       t        d|j
                          Y d}~yd}~wt        $ r$ t        d       t        d       t        d       Y yw xY w)za
    Run an ffmpeg command and handle errors.
    Returns True on success, False on failure.
    u   
🔧 z...z   Command:  Tcapture_outputr   checku   ✅ z	 completeu   ❌ z failedz
   Error: NFu,   ❌ ffmpeg not found. Please install ffmpeg:z*   Ubuntu/WSL: sudo apt-get install ffmpegz   macOS: brew install ffmpeg)r   r   
subprocessrunCalledProcessErrorstderrFileNotFoundError)commanddescriptionresultr#   s       r   run_ffmpeg_commandrS      s    
 
GK=
$%	L'*+
,-	
 	[M+,(( [M)*
188*%& <>:<-/	s   (A C*'B-CCc           	      P    dddt        |       ddt        |      g}t        |d      S )z2Normalize audio volume to -16 LUFS (web standard).ffmpeg-y-i-afzloudnorm=I=-16:TP=-1.5:LRA=11zNormalizing volumer   rS   
input_fileoutput_filerP   s      r   normalize_audior]      s7     	$c*o.K	G g';<<r   c           	      P    dddt        |       ddt        |      g}t        |d      S )z$Remove leading and trailing silence.rU   rV   rW   rX   zsilenceremove=start_periods=1:start_silence=0.1:start_threshold=-50dB,areverse,silenceremove=start_periods=1:start_silence=0.1:start_threshold=-50dB,areversezTrimming silencerY   rZ   s      r   trim_silencer_      s;     	$c*o
 	K
G g'9::r   c                 d    dddt        |       dddt        ddd	d
t        |      g}t        |d      S )z0Convert to WebM/Opus format (optimized for web).rU   rV   rW   -c:alibopus-b:az-vbronz-compression_level10zConverting to WebM/Opus)r   OPUS_BITRATErS   rZ   s      r   convert_to_opusrg      sE     	$c*o	dKG g'@AAr   c                 ~    dddt        |       dddt        ddd	t        t              t        |      g}t        |d
      S )z4Convert to MP3 format (fallback for older browsers).rU   rV   rW   ra   
libmp3lamerc   z-ac1z-arzConverting to MP3)r   MP3_BITRATEr4   rS   rZ   s      r   convert_to_mp3rl      sJ     	$c*oss;KG g':;;r   c           
          	 dddddddt        |       g}t        j                  |ddd	      }t        |j                  j                               }|S # t        $ r}t        d
|        Y d}~yd}~ww xY w)z)Get duration of audio file using ffprobe.ffprobez-verrorz-show_entrieszformat=durationz-ofz"default=noprint_wrappers=1:nokey=1TrH   u    ⚠️  Could not get duration: N)r   rK   rL   floatstdoutr   r   r   )
audio_filerP   rR   durationr#   s        r   get_audio_durationrt      s}    tW.7
O	
 4tT,,./ 045s   AA 	A4A//A4c                  B   t        d       t        d       t        d       t        dz  } t        dz  }d}| j                         r| j                         j                  dz  }t        |       }t        d       t        d	| j                          t        d
|dd|dk  rdnd        t        |rd|ddnd       |dkD  rd}nt        d       d}|j                         r|j                         j                  dz  }t        |      }t        d       t        d	|j                          t        d
|dd|dk  rdnd        t        |rd|ddnd       |dkD  rd}nt        d       d}t        d       |rt        d       nt        d       t        d       |S )z0Verify the final output files meet requirements.G
======================================================================zVERIFICATION REPORTF======================================================================	demo.opusdemo.mp3Tr0   u   
📦 WebM/Opus (Primary)z	   File: z	   Size: r1   z KB i^  u   ✅u   ⚠️  (>350KB)z   Duration: sz   Duration: UnknownFu   
❌ WebM/Opus file not foundu   
📦 MP3 (Fallback)i  u   ⚠️  (>500KB)u   
❌ MP3 file not foundu,   ✅ ALL CHECKS PASSED - Ready for deploymentu0   ⚠️  Some checks failed - review output above)r   r   existsstatst_sizert   name)	opus_filemp3_fileall_good	opus_sizeopus_durationmp3_sizemp3_durations          r   verify_output_filesr     s   	-	
 	&M[(IJ&HH NN$,,t3	*95*,	)..)*+	)Ci#oUK],^_`mmC02I_`s?H.0 ==?**T1)(3%'	(--)*	(3tX^EI[+\]^\l3/q1G]^c>H(*	-<=@A	&MOr   c                      t        d       t        d       t        d       t        dj                  t        t                     t        d       y)zPrint deployment instructions.rv   z
NEXT STEPSrw   a~  
1. Listen to the generated audio files:
   - {}/demo.opus (primary)
   - {}/demo.mp3 (fallback)

2. If satisfied, deploy to website:
   - Upload both files to website assets folder
   - Update hero video HTML:

     <audio>
       <source src="/assets/audio/demo.opus" type="audio/webm; codecs=opus">
       <source src="/assets/audio/demo.mp3" type="audio/mpeg">
     </audio>

3. Test on multiple browsers:
   - Chrome (Opus)
   - Firefox (Opus)
   - Safari (Opus/MP3)
   - Edge (Opus)
   - Mobile (iOS + Android)

4. Monitor performance:
   - Check loading time (<2s on 3G)
   - Verify autoplay behavior
   - Track engagement metrics
G======================================================================
N)r   formatr   r   r   r   print_next_stepsr   <  s>    	-	,	&M	 2 F:z"3$4 
-r   c                     t        d       t        d       t        d       t        dt         d       t        dt                t        d       t                t	               } | t
        } t        |       }| t        d	       t        j                  d
       t        |d      }| t        d       t        j                  d
       t        dz  }t        dz  }t        dz  }t        dz  }t        ||      st        d       |}t        ||      st        d       |}t        ||      st        d       t        ||      st        d       t                t                t        d       y)zMain execution flow.rv   zAIVA DEMO RECORDING SCRIPTrw   zVoice: z& (AIVA - Australian Female Premium HD)zOutput: r   Nu(   
❌ Failed to generate audio. Aborting.r   zdemo_raw.wavu(   
❌ Failed to save raw audio. Aborting.zdemo_normalized.wavzdemo_trimmed.wavrx   ry   u5   
⚠️  Volume normalization failed, using raw audiou8   
⚠️  Silence trimming failed, using normalized audiou   
❌ Opus conversion failedu   
❌ MP3 conversion failedu   ✅ RECORDING COMPLETE
)r   r2   r   r   r$   FALLBACK_SCRIPTr<   sysexitrE   r]   r_   rg   rl   r   r   )r"   rA   raw_filenormalized_filetrimmed_filer   r   s          r   mainr   b  sQ   	-	
&'	&M	GJ<E
FG	HZL
!"	-  ()K% !-J9: z>:H9: !#88O 22L[(IJ&H 8_5FG" 6IJ& <3,- ,1+,  	
$%r   __main__u'   

⚠️  Interrupted by user. Exiting.u   
❌ Unexpected error: r   ))__doc__osr   r-   rK   pathlibr   r5   docxr   r3   r7   r2   	REPO_ROOTr   r   r4   rf   rk   r   r   r$   r<   rE   rS   r]   r_   rg   rl   rt   r   r   r   __name__KeyboardInterruptr   r   r   r#   	traceback	print_excr   r   r   <module>r      s>   
 
      N;
 ()	**-]]))H4w>
 L.76(V:=; B<"4nL;&| z	   9: (,-		s   9B C##C#'2CC#