Python  .    
 


      .    ,    Python.     ? .                .     ? .           ,     ,      .

 ,     ,     .   ,         ,   .     -,    .           .    ,    ,   .          ,       ,    .

 .      .     Python.





Python  .    








    

      .                .            Delete.         .      .  ,   .      ,     .

  .     .     ,   ,    .       ,  ,  ,  -    ,      .      .   .   .   Python  .       ,        .

 -      : ?          ?     :    .   ,         .   ,        .   ,     .   ,     LUFS        .   ,       .

   .  ,    .     ,    .       .      .       ,   .   .           .         .        .            .

      ,       .   ,  ,   .        .  ,  ,  ,     ,  ,    ,   .  - : ,     ? ?  : Python.   .     .      .

      .    ,     .     ,    .  , , , ,      ,          .    ,       : ,  ,   ,   ,   .

 

    .      .       ,       ,    .            4,   .        3   .    ,     .

      . ,         ,       Python.    ,     : , ,  .  .

      .       ,     ,  ,   .  ,      .

      . ,   LUFS        .      YouTube, Spotify  .    ,      .

      .    :       .           .

      .         .   -,   ,       .     ,     .

       .          .   : , , , , .       . ,         .

       .     ,   ,      .      ,       .

      .       .       .     .      ,      .

           .    ,            .    ,        .

     ,       .

   

    .        ,   ,      .           ,     .  ,   ,     .          .      ,       .        .             .         .

        .    Python, ,    .       .    .     .    ,  ,     .







    ,            .       ,   librosa, numpy, noisereduce    ,     .   , ,  ,              .    .

.




.  Python,   Audacity?


   

:      YouTube.   ,    ,    .         .

   .       :   ,    , ,   .

?  . ?  -  .

   ,       ,    .      .           Audacity, Adobe Audition  Reaper.     .     .  Python   .

  Python,        ?  .

   Python    

 : .

,       .         ,      .  Audacity    :  ,  , , ,  .  .

 Python     .        .  Audacity  ,         .

 : .

           .   ,     .  :  ?    .   ,  ,     .

     .  :       12 .      .  :           .     .  .  .

 : .

 .   ,      ,    .  Audacity  :  ,   , ,  .    .

 Python  :     ,   .      ,   .       ,    .



      Python

     .     ,    , ,     ,       ,  . .

    .    ,    ,  .

    :



 ,     ,     ,   .

      Python:

python

import librosa

import soundfile as sf



y, sr = librosa.load('podcast.wav')

y_trimmed, _ = librosa.effects.trim(y, top_db=20)

sf.write('podcast_clean.wav', y_trimmed, sr)

     .            . .

  Python     .       ,       .            .      ,   ,   .

 , ,  ,           .  Python      ,    .

  

  .   .   :

: .



   Windows, Mac, Linux. Python   .         ,     .

: Python  3.9  .



     Python   .         .   :  ,    , .

:       .



    ,     .

   

    .       ,      .     .      .

        :

  .     . ,   .

    .   ,     .

. ,    .       .

 .         .            .

 .  :    .    ,     .     ,     ,  welcome.

 .        ,      .

-.   .     .

   ,    ,     :   ,  ,  , .   .

 Python   

    ,    .         Python    .

 1.  Python.

   python.org (https://python.org/).          Download Python 3.x   x     .      3.12,    ,   3.9.   .  .

 2.  .

  , . :          Add Python to PATH.   .    Python ,      ,   .  ?  Install Now.

 . .

 3. .

 ,   .      Windows ( Win,   cmd,  Enter)    Mac  Linux.

   :

bash

python --version

  Enter.      Python 3.12.1  , Python  .

      ,    Add Python to PATH.  :  Python       .    ,     .

 4.  .

   Python     .  ,   .          .

        ,  Enter  :

bash

pip install librosa

pip install soundfile

pip install noisereduce

   , , .   ,       .      .

  pip     pip3  pip.     Mac  Linux.    pip3 install librosa   .

 5.   .

 ,     .      audio_book.        hello_sound.py.

:     .py,   .txt. Windows     ,  ,     hello_sound,      hello_sound.py.txt.   ,  ,    ,     .         .py  .

 hello_sound.py    .    ,     VS Code       ,    .

     :

python

import librosa

print(" librosa   !")

print("   .")

 .     .      audio_book.       ,   :

bash

cd Desktop/audio_book

 Enter.       .  :

bash

python hello_sound.py

    :

text

 librosa   !

   .

   .         Python-.    ,    .

   

    ,    .   -       ,   .      ,         .     Python  ,    .        .

:   .       .    :    ,  .            .    ,    .

:         .  ,    , , , .      .  ,  .

      

 .    ,          .    .           :

      ,       ,     , ,   .     .     .

    .    ,  -    ,    - .   ,      .     ,       .

     .  ,   -        .   .      ,     .    , , .

   .    YouTube   ,    .         ,    .        -     .

   .       ?      ?      -   ?       .

       .     ,    .       ,     ,   ,  ,   .   .  .

       ,      -.   , ,  ,        :     ?

  :     .  ,      ,    .     ,    ,   .  ,   .

 :     Python  

,        ?  .  ,  .

    .  ,   .   ,   ,   .            .        .

    .  :   .   .  , ?

  :    . ,    ?

 :    .     .

  .     .      ,       .       .        .

, .   Audacity.      .     ,  , ,  ,  , ,  .       ,      .      ,    .         .        .

  :   .     ,   ?

  Python.  librosa.        .   .      ,     .     ,      .

       ,     Audacity.         .      : ,      ?  .

    ,      .        Python.

       ,     ,      .      .      ,     .

  :     

    :   ,   .   .    .   .    ,  ,     .

.     ,      .    ,    .      ,     ,   ,    ,     .           .

.     . .   ,     .    . ,   Python  ,      . -?   ,        ,    .  ?        ,        .  .  .  .

.     .       .     ,      .  . .    ,     ,       .    ,    .

.       .    ,          .           ,    - .          .       -        .       .   .    ,  .

  :  

       .     ,       .   .

  .



           . .   .   .   .    . .  .       .       .       ,     .

  .



      ,   ,   .    .       .          ,   ,    ,   .           .     ,  .

  .



  ,   .   ,   ,   .           .    ,      .  ,    ?     ,       ?         ? .         .

   ,  :         .  4     13.   .     -    9  .         4.     ,     .    .




 1.     Python


   ,   .         

   

 -         ,   ?     , , : ,     ?          ,   .     Python,          ,    .     , ,    .     ,      .  ,      .      ,       ,    .     ,   :        ,            - .

    

    .   , ,  .    .      ?    .    ,     .          .   ,          .  ,            .      :       .             .

    .      ,      .                  .    ,   .                   .    .  ,   :    ,       .             .        ,  ,        ,    .

   ,        ?    .  ,     :      ,       ,    .           . ,   ,   ,        .             ,   .            ,     .         ,        .         .                  .

     .            .            .         ,     .      .    ,  .     :   ,   ,    .      ,  ,     .      ,      .      ,   .     .       ,     ,    .

  

      ,    .     :     ,  .   Python    ,         .              ,       .     ,    .

 Python    .    python.org (https://python.org/).         Download Python   .   .  .  .        ,   Add Python to PATH.    : ,   Python,        .    ,      .  ,   Python        .   Install Now   . , Python   .

 ,  Python .    ,    Windows    Windows,    cmd,  Enter.    Mac  Linux,  .       python --version   Enter.  Python ,   -  Python 3.12.1   .   ,  ,        .  Python,  ,   .

    .   Python      .    Python  ,         .  ,     .          ,  Enter  :

pip install librosa



pip install soundfile



pip install sounddevice

         .         .   ,       .  ,   .

   ? librosa         .    ,  ,    . soundfile       . sounddevice      ,      .           .

        ,  audio_book.           .      .       ,        .

  :  

     .    .       ,    .      ,   ,    .      ,    ,  .

   .  Windows   ,       Visual Studio Code   ,          .            first_script.py.  .py  ,     Python.  :      .txt, Python  ,   .

     .                 ,  .    ,      .  Python    : Print  print      .    ,   .

python

import librosa



y, sr = librosa.load('my_voice.wav')



print(" !")

print(f" : {sr}   ")

print(f" : {len(y) / sr:.2f} ")

print(f"   : {len(y)}")

 .     .     ,    .      cd Desktop/audio_book   Enter. cd  change directory,    .        .

   ,   .          WAV,     audio_book    my_voice.wav.     .    ,      ,      ,     .    ,    audio_book   my_voice.wav.  WAV : librosa      WAV-.      ,  MP3  M4A,      WAV     Audacity  -.     ,      ,      WAV.

 .     python first_script.py   Enter.    ,     - :

text

 !

 : 22050   

 : 58.34 

   : 1286397

!           Python.    :       .   ,   .

 :   

import librosa      Python:       librosa,   .   Python      .   ,        .         .    Python   ,       .

y, sr = librosa.load('my_voice.wav')     .     . -,      my_voice.wav    ,   . -,           ,    . -,     .       y.         .      sr,         .            y  sr,       .       ,         ,  .

print(" !")     .  print    Python   . ,     ,   .    ,  ,        .

print(f" : {sr}   ")       ,   f-.  f     Python:       ,  ,   ,     . Python    {sr}, ,    sr   22050,     ,       : 22050   .   .

print(f" : {len(y) / sr:.2f} ")      . len(y)   ,     y,       .       sr     .   .2f    Python:       ,   .     ,   58.34 ,   58.3412345...    .

print(f"   : {len(y)}")        .        . ,  ?     ,     .   ,         .       .



 :  

,          ,    .       .     :

python

import numpy as np



max_volume = np.max(np.abs(y))

min_volume = np.min(y)

avg_volume = np.mean(np.abs(y))



print(f"  : {max_volume:.4f}")

print(f"  : {min_volume:.4f}")

print(f" : {avg_volume:.4f}")

       numpy.       .          . np    ,      ,    numpy   .  np  ,    .

np.max(np.abs(y))         .  np.abs(y)    y       ,    .       .       .   ,      : ,      ,       .  np.max       .          .

np.min(y)       ,   .    ,    .        :      , ,  ,  .       , ,   -    ,   .

np.mean(np.abs(y))    .      ,        ,     .    ,     ,     .       ,    .      ,       .     ,      .

    

   ,      .       Python-.      sounddevice,   .    :

python

import sounddevice as sd



print("   ...")

sd.play(y, sr)

sd.wait()

print(" .")

sd.play(y, sr)  :    y     ,    sr   .              .     : sd.wait()  :    ,    .    ,       ,     .    ,  .

         .     WAV-,   ,  ,    ,    .                .

   

        .   ,   ,  :  ,  ,        .    ,     .        .      .      ,        .

 librosa      .   split    ,   :     ,    . ,      .      :

python

import librosa

import numpy as np



y, sr = librosa.load('my_voice.wav')



intervals = librosa.effects.split(y, top_db=30)



total_speech = 0

for start, end in intervals:

duration = (end - start) / sr

total_speech += duration



total_length = len(y) / sr

silence = total_length - total_speech



print(f"  : {total_length:.2f} ")

print(f" : {total_speech:.2f} ")

print(f" : {silence:.2f} ")

print(f"  {silence / total_length * 100:.1f}  ")

 ,   . librosa.effects.split(y, top_db=30)   ,     y   ,   ,    .  top_db=30   .  30 ,  ,         30 ,  .    ,        .    ,     20   15              .

   .      :     ,       .   for start, end in intervals       .       : (end - start) / sr.            .       total_speech.

        len(y) / sr.    : ,     .    .

       , ,  , ,         .     ,     .      . :        ,   .  ,       .

    

     WAV.   : MP3, M4A, FLAC, OGG, WMA   .     ,   . ,  ,      ,     .

WAV     .  ,       ,  -    .   ,          . WAV      .        WAV,      . ,                  .    .   :   WAV,       MP3  .

MP3         .  MP3      ,       .               WAV.     :     ,        .    MP3  ,       .

M4A   ,   MP3,     .       M4A  ,   MP3. FLAC     .  ,  WAV,  ,  MP3,      .    FLAC   .     Python  WAV  .

       , librosa         .      pydub,       .    pip install pydub,        WAV   .           ,        WAV.

    

   .               .  ,          ,       .       Python,   ,     ,    .  ,   WAV   ,  MP3   .    ,      .

    ,    .     ,      . ,        , ,  ,  ,     . ,     ,      ,     .       ,   :  .

 

     ,      .        .       .       .          .  .   ?  , ,  , ,  ?        ?         ,   .        ,  .       .

          :   ,   ,     .           .  ,          .        .

 :     .   top_db  30  20,  40,  10. ,   .       ,    .      ,        ,   .     ,  .    ,   .

- 

   , : ,        ,  ; ,         22050  ;   Python    pip;   WAV-  Python   librosa.load;    ,    ;       sounddevice;         librosa.effects.split;     WAV, MP3, FLAC  ,    ;      Python-   .         :  ,    ,   .




 2.     


   

          .    ,     .     .          :  ,  ,   .  ,        Audacity,    .  ,   ?      .          .         ,       .      ,            .      ,     ,    ,           .       ,         .

    

    :       . ,    .   ,  ,  -,  ?,   ,          .         .  ,    ,  ,  -  ,  . ,   ?  , .       .            Delete.       ,        .

,        y.      ,  .     ,    ,     .  Python      ,          .   .       ,          ,   .      :       ,     22050,    . ,             .

     :

python

import librosa

import soundfile as sf



y, sr = librosa.load('long_record.wav')



#     

cut_seconds = 180

cut_samples = cut_seconds * sr



#  ,   cut_samples   

y_trimmed = y[cut_samples:]



sf.write('record_trimmed.wav', y_trimmed, sr)

print(f": {len(y) / sr:.1f} ")

print(f": {len(y_trimmed) / sr:.1f} ")

 y[cut_samples:]     .    Python,      .      .          . ,     cut_samples, .  :        y.     y_trimmed,      .    ,       .

  :  .   ,     ,    :

python

#     

cut_end_seconds = 10

cut_end_samples = len(y) - (cut_end_seconds * sr)



#      cut_end_samples

y_trimmed = y[:cut_end_samples]

  y[:cut_end_samples]      cut_end_samples,   .              .        .

    ,   ,       :

python

y_trimmed = y[180 * sr : len(y) - 10 * sr]

  :   y  ,    ,  ,       .    .

  

  .     . ,     :  ,     .      ,    .        .      np.concatenate   numpy.           ,      .

  :

python

import librosa

import numpy as np

import soundfile as sf



#   

intro, sr1 = librosa.load('intro.wav')

voice, sr2 = librosa.load('voice.wav')

outro, sr3 = librosa.load('outro.wav')



# 

final = np.concatenate([intro, voice, outro])



# 

sf.write('final.wav', final, sr1)

    :        .      44100,    22050,     48000,     .      ,      ,  .     ,      ,         .

      :

python

import librosa

import numpy as np

import soundfile as sf



#    

target_sr = 22050



intro, sr_i = librosa.load('intro.wav', sr=target_sr)

voice, sr_v = librosa.load('voice.wav', sr=target_sr)

outro, sr_o = librosa.load('outro.wav', sr=target_sr)



print(f": {len(intro) / target_sr:.1f} ")

print(f": {len(voice) / target_sr:.1f} ")

print(f": {len(outro) / target_sr:.1f} ")



# 

final = np.concatenate([intro, voice, outro])

print(f": {len(final) / target_sr:.1f} ")



sf.write('episode.wav', final, target_sr)

 sr=target_sr   librosa.load  :      ,        target_sr.        , librosa     .         .

   

      ,    .              ,       .         .      .    ,          .   22050   22050 .

python

#     

silence_sec = 1.0

silence = np.zeros(int(target_sr * silence_sec))



#   

final = np.concatenate([intro, silence, voice, silence, outro])

 np.zeros(n)    n .     ,      ,    .        ,         .       .            .  ,   ,   .

  

        .      ,  .     ,          .  .   ,       .

        ,       1,      3.    :

python

def normalize_volume(y, target_peak=0.9):

"""     ."""

current_peak = np.max(np.abs(y))

if current_peak == 0:

return y

gain = target_peak / current_peak

return y * gain



#   

intro = normalize_volume(intro, 0.9)

voice = normalize_volume(voice, 0.9)

outro = normalize_volume(outro, 0.9)

          ,        .

   

        ,         .         ,    .

python

import librosa

import numpy as np

import soundfile as sf



def build_podcast(intro_file, voice_file, outro_file, output_file,

trim_start=180, trim_end=10,

silence_between=1.0,

target_sr=22050,

target_peak=0.9):

"""

     .

trim_start -       

trim_end -       

silence_between -      

"""

print("===   ===")



# 

print(" ...")

intro, _ = librosa.load(intro_file, sr=target_sr)

voice, _ = librosa.load(voice_file, sr=target_sr)

outro, _ = librosa.load(outro_file, sr=target_sr)



#  

start_sample = int(trim_start * target_sr)

end_sample = len(voice) - int(trim_end * target_sr)

voice = voice[start_sample:end_sample]

print(f"  : {len(voice) / target_sr:.1f} ")



#  

for arr in [intro, voice, outro]:

peak = np.max(np.abs(arr))

if peak > 0:

arr *= target_peak / peak



#  

silence = np.zeros(int(target_sr * silence_between))



# 

final = np.concatenate([intro, silence, voice, silence, outro])

print(f" : {len(final) / target_sr:.1f} ")



# 

sf.write(output_file, final, target_sr)

print(f": {output_file}")

print("!")



# 

build_podcast(

intro_file='intro.wav',

voice_file='raw_voice.wav',

outro_file='outro.wav',

output_file='episode_ready.wav',

trim_start=180,

trim_end=10,

silence_between=1.0

)

  ,   .          ,            .    .    ,      ,    .

 :    

              . ,       ,         ,       .  Audacity    .  Python       .

python

import os

import librosa

import soundfile as sf



input_folder = 'raw_recordings'

output_folder = 'trimmed_recordings'




  .


   .

   ,     (https://www.litres.ru/pages/biblio_book/?art=74000411)  .

      Visa, MasterCard, Maestro,    ,   ,     ,  PayPal, WebMoney, ., QIWI ,       .


