
    rho                        S SK Jr  S SKrS SKJr  S SKJr  \R                  " S5      r  SS jrSS jr	 " S S	\R                  5      r\S
:X  a  S SKr\R                  " \5        gg)    )annotationsN)environment)scalezaudioSearch.transcriberc                   SSK Jn  Uc  [        R                  " S5      nUSL a  [        R                  5       S-  nO
USL a  SnOUnUSL a  UR                  U[        U5      S9nOUR                  [        U5      S	9nUR                  X5      n	UR                  U	5      n	UR                  X5      u  n
nUR                  U
5      u  nnUR                  UUSS
9u  pU (       a  UR                  5         U(       a:   SSKnUR$                  R'                  U5        UR$                  R                  5         [        R)                  S5        U$ ! [          a    UR#                  S5      ef = f)am  
runs all the methods to record from audio for `seconds` length (default 10.0)
and transcribe the resulting melody returning a music21.Score object

if `show` is True, show the stream.

if `plot` is True, then a Tk graph of the frequencies will be displayed.

if `useMic` is True then use the microphone.  If False it will load the file of `saveFile`
or the default temp file to run transcriptions from.

a different scale than the chromatic scale can be specified by setting `useScale`.
See :ref:`moduleScale` for a list of allowable scales. (or a custom one can be given).
Microtonal scales are totally accepted, as are retuned scales where A != 440hz.

if `saveFile` is False, then the recorded audio is saved to disk.  If
set to `True` then `environLocal.getRootTempDir() / 'ex.wav'` is
used as the filename.  If set to anything else then it will use that as the
filename.
r   audioSearchNC4Tzex.wavF)lengthstoreWaveFilenamewaveFilenameremoveRestsAtBeginningz)Cannot plot without matplotlib installed.z* END)music21r   r   ChromaticScaleenvironLocalgetRootTempDirgetFrequenciesFromMicrophonestrgetFrequenciesFromAudioFiledetectPitchFrequenciessmoothFrequenciespitchFrequenciesToObjectsjoinConsecutiveIdenticalPitchesnotesAndDurationsToStreamshowmatplotlib.pyplotImportErrorAudioSearchExceptionpyplotplot
printDebug)r   r!   useMicsecondsuseScalesaveFileaudioSearchBaser   freqFromAQListdetectedPitchesFreqdetectedPitchObjectslistplot	notesListdurationListmyScoreunused_length_part
matplotlibs                    Y/home/james-whalen/.local/lib/python3.13/site-packages/music21/audioSearch/transcriber.pyrunTranscriber2      s   , 7''-4#224x?	U	 ~(EE!,/ F 1 )DD\* E , *@@Z);;<OP#==>Q\'GGH\]Y"1"K"K# #L #%G
 	=$ 	x( G$N  	=!66;= =	=s   :E
 
E&c                   SSK Jn  UR                  U S9nUR                  X15      nUR	                  U5      nUR                  XA5      u  nnUR                  U5      u  nnUR                  XxSS9u  pU	R                  R                  5       $ )a  
Reads in a .wav file and returns a stream representing the transcribed, monophonic audio.

`fileName` should be the complete path to a file on the disk.

A different scale than the chromatic scale can be specified by setting `useScale`.
See :ref:`moduleScale` for a list of allowable scales. (or a custom one can be given).
Microtonal scales are totally accepted, as are retuned scales where A != 440hz.

We demonstrate with an audio file beginning with an ascending scale.

>>> import os #_DOCS_HIDE
>>> taw = 'test_audio.wav' #_DOCS_HIDE
>>> waveFile = str(common.getSourceFilePath() / 'audioSearch' / taw) #_DOCS_HIDE
>>> #_DOCS_SHOW waveFile = 'test_audio.wav'
>>> p = audioSearch.transcriber.monophonicStreamFromFile(waveFile)
>>> p
<music21.stream.Part ...>
>>> p.show('text')
{0.0} <music21.note.Note C>
{0.25} <music21.note.Note C>
{0.75} <music21.note.Note D>
{1.75} <music21.note.Note E>
{2.75} <music21.note.Note F>
{4.25} <music21.note.Note G>
{5.25} <music21.note.Note A>
{6.25} <music21.note.Note B>
{7.25} <music21.note.Note C>
...
r   r   r   Tr   )
r   r   r   r   r   r   r   r   partsfirst)fileNamer%   r'   r(   r)   r*   unused_listplotr,   r-   r.   r/   s              r1   monophonicStreamFromFiler8   ^   s    > 7$@@h@WN)@@Z);;<OP*DDEXc'GGH\]Y"1"K"K #L #>G==      c                       \ rS rSrS rS rSrg)TestExternal   c                J    [         R                  5       S-  n[        SSUSS9  g )Nznew_song.wavFg      $@)r   r!   r&   r$   r   r   r2   selfr&   s     r1   x_testRunTranscribe TestExternal.x_testRunTranscribe   s#    ..0>A5uxNr9   c                J    [         R                  5       S-  n[        SUSSS9  g )Nzpachelbel.wavF)r#   r&   r!   r   r>   r?   s     r1   x_testTranscribePachelbel&TestExternal.x_testTranscribePachelbel   s#    ..0?BUXENr9    N)__name__
__module____qualname____firstlineno__rA   rD   __static_attributes__rF   r9   r1   r;   r;      s    OOr9   r;   __main__)TTTg      4@NT)N)
__future__r   unittestr   r   r   Environmentr   r2   r8   TestCaser;   rG   mainTestrF   r9   r1   <module>rR      sm    #   &&'@A 048<DN+!\O8$$ O z\" r9   