
    rh                    b   % S r SSKJr  SSKJr  SSKrSSKrSSKJr  SSK	J
r
  SSK	Jr  \
R                  " S5      rS	rS
rSrSSS\\\4S jr " S S\R$                  5      r " S S\R(                  5      r " S S\R(                  5      r/ rS\S'   \S:X  a  SSK	r	\	R4                  " \5        gg)a  
modules for audio searching that directly record from the microphone.

Requires PyAudio and portaudio to be installed (https://www.portaudio.com/download.html)

Windows users will get pyaudio and portaudio with `pip install pyaudio`

macOS users should have Homebrew installed and run `brew install portaudio`
before running `pip install pyaudio`

There is no official support for Linux/BSD etc. in music21, but package managers like `apt`
tend to have libraries like `portaudio19` and `python3-pyaudio`.
    )annotations)	find_specN)DocOrder)environment)exceptions21zaudioSearch.recording   iD  i   g      $@Tc                Z   SSK nUR                  nUc  UnX&R                  :X  a  [        S5      eUR	                  5       nUR                  UUUSUS9n	[        U[        U 5      -  U-  5      n
/ n[        U
5       H%  nU	R                  U5      nUR                  U5        M'     U	R                  5         UR                  5         USLa  [        U[        5      (       a  UnO [        [        R!                  5       S-  5      nSR#                  U5      n [$        R
                  " US	5      nUR'                  U5        UR)                  UR+                  U5      5        UR-                  U5        UR/                  U5        UR                  5         U$ U$ ! [0         a    [        S
U S35      ef = f)z
records `seconds` length of sound in the given format (default Wave)
and optionally stores it to disk using the filename of `storeFile`

Returns a list of samples.
r   Nz4cannot perform samplesFromRecording on 8-bit samplesT)formatchannelsrateinputframes_per_bufferFzrecordingTemp.wav    wbzCannot open z for writing.)pyaudiopaInt16paInt8RecordingExceptionPyAudioopenintfloatrangereadappendclose	terminate
isinstancestrenvironLocalgetRootTempDirjoinwavesetnchannelssetsampwidthget_sample_sizesetframeratewriteframesIOError)seconds	storeFilerecordFormatrecordChannelsrecordSampleRaterecordChunkLengthr   recordFormatDefaultp_audiostrecordingLengthstoredWaveSampleListidatawaveFilenamewfs                   W/home/james-whalen/.local/lib/python3.13/site-packages/music21/audioSearch/recording.pysamplesFromRecordingr:   *   s    !//*~~% !WXXooG	\-+ (9	 
 
;B *U7^;>OOPO ?#ww()##D) $ HHJi%%$L|::<?RRSLxx,-		Q<.BOON+OOG33LABOO,-NN4 HHJ    	Q$|L>%OPP	Qs   A:F F*c                      \ rS rSrSrg)r   f    N__name__
__module____qualname____firstlineno____static_attributes__r=   r   r9   r   r   f       r   r   c                      \ rS rSrSrg)Testk   r=   Nr>   r=   r   r9   rF   rF   k   rD   r   rF   c                  f    \ rS rSr\" S5      r\b  SrOSr\R                  " \S5      S 5       r	Sr
g)	TestExternaln   r   NTFzpyaudio must be installedc                4    [        SSS9n[        USS 5        g)z0
record one second of data and print 10 records
r   F)r*   r+      (   N)r:   print)self
sampleLists     r9   testRecordingTestExternal.testRecordingu   s    
 *!uE
jB r   r=   )r?   r@   rA   rB   r   loaderpyaudio_installedunittest
skipUnlessrQ   rC   r=   r   r9   rI   rI   n   s@    y!F !*,GH! I!r   rI   r   
_DOC_ORDER__main__)__doc__
__future__r   importlib.utilr   rU   r#   music21.common.typesr   music21r   r   Environmentr    default_recordChannelsdefault_recordSampleRatedefault_recordChunkLengthr:   Music21Exceptionr   TestCaserF   rI   rW   __annotations__r?   mainTestr=   r   r9   <module>rf      s    # $   )   &&'>?      "&&*(>*B+D	9 x	66 	
	8 	!8$$ !$ 
H  zT r   