changeset 49:809df9157e1a

Merge branch 'master' of https://github.com/amsehili/auditok
author Amine SEHILI <amine.sehili@gmail.com>
date Sun, 06 Mar 2016 14:57:03 +0100
parents 117856eabb9e (diff) 3e939c1049dc (current diff)
children 308c89235a2e
files
diffstat 5 files changed, 18 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/auditok/cmdline.py	Fri Dec 11 21:23:08 2015 +0100
+++ b/auditok/cmdline.py	Sun Mar 06 14:57:03 2016 +0100
@@ -566,7 +566,7 @@
         group.add_option("-n", "--min-duration", dest="min_duration", help="Min duration of a valid audio event in seconds [default: %default]", type=float, default=0.2, metavar="FLOAT")
         group.add_option("-m", "--max-duration", dest="max_duration", help="Max duration of a valid audio event in seconds [default: %default]", type=float, default=5, metavar="FLOAT")
         group.add_option("-s", "--max-silence", dest="max_silence", help="Max duration of a consecutive silence within a valid audio event in seconds [default: %default]", type=float, default=0.3, metavar="FLOAT")
-        group.add_option("-d", "--drop-trailing-silence", dest="drop_trailing_silence", help="Drop trailing silence from a detection [default: do not play]",  action="store_true", default=False)
+        group.add_option("-d", "--drop-trailing-silence", dest="drop_trailing_silence", help="Drop trailing silence from a detection [default: keep trailing silence]",  action="store_true", default=False)
         group.add_option("-e", "--energy-threshold", dest="energy_threshold", help="Log energy threshold for detection [default: %default]", type=float, default=50, metavar="FLOAT")
         parser.add_option_group(group)
         
@@ -635,7 +635,7 @@
             handler.setLevel(logging.DEBUG)
             logger.addHandler(handler)
         
-        record = opts.output_main is not None or opts.plot
+        record = opts.output_main is not None or opts.plot or opts.save_image is not None
                         
         ads = ADSFactory.ads(audio_source = asource, block_dur = opts.analysis_window, max_time = opts.max_time, record = record)
         validator = AudioEnergyValidator(sample_width=asource.get_sample_width(), energy_threshold=opts.energy_threshold)
@@ -645,9 +645,11 @@
             mode = StreamTokenizer.DROP_TRAILING_SILENCE
         else:
             mode = 0
-        tokenizer = StreamTokenizer(validator=validator, min_length=opts.min_duration * 100,
-                                    max_length=int(opts.max_duration * 100),
-                                    max_continuous_silence=opts.max_silence * 100,
+        
+        analysis_window_per_second = 1. / opts.analysis_window
+        tokenizer = StreamTokenizer(validator=validator, min_length=opts.min_duration * analysis_window_per_second,
+                                    max_length=int(opts.max_duration * analysis_window_per_second),
+                                    max_continuous_silence=opts.max_silence * analysis_window_per_second,
                                     mode = mode)
         
         
@@ -683,7 +685,7 @@
                 player_worker = PlayerWorker(player=player, debug=opts.debug, logger=logger)
                 observers.append(player_worker)
             except Exception:
-                sys.stderr.write("Cannot get a audio player!\n")
+                sys.stderr.write("Cannot get an audio player!\n")
                 sys.stderr.write("You should either install pyaudio or supply a command (-C option) to play audio\n")
                 sys.exit(2)
                 
@@ -784,4 +786,4 @@
         stats.print_stats()
         statsfile.close()
         sys.exit(0)
-    sys.exit(main())
\ No newline at end of file
+    sys.exit(main())
--- a/auditok/core.py	Fri Dec 11 21:23:08 2015 +0100
+++ b/auditok/core.py	Sun Mar 06 14:57:03 2016 +0100
@@ -274,7 +274,7 @@
         order to detect sequences of frames that make up valid tokens.
         
         :Parameters:
-           `data_source` : instance of the `DataSource` class that implements a 'read' method.
+           `data_source` : instance of the :class:`DataSource` class that implements a `read` method.
                'read' should return a slice of signal, i.e. frame (of whatever \
                type as long as it can be processed by validator) and None if \
                there is no more signal.
@@ -303,7 +303,7 @@
         
         while True:
             frame =  data_source.read()
-            if frame == None:
+            if frame is None:
                 break
             self._current_frame += 1
             self._process(frame)
--- a/auditok/io.py	Fri Dec 11 21:23:08 2015 +0100
+++ b/auditok/io.py	Sun Mar 06 14:57:03 2016 +0100
@@ -162,7 +162,7 @@
                 seconds to skip from the start of the stream
         """
         pass
-    
+
     
 
 class BufferAudioSource(AudioSource, Rewindable):
@@ -196,7 +196,6 @@
         self.rewind()
     
     def read(self, size):
-        
         if not self._is_open:
             raise IOError("Stream is not open")
         
@@ -272,12 +271,10 @@
 
 
     def set_time_position(self, time_position): # time in seconds
-        
         position = int(self.sampling_rate * time_position)
         self.set_position(position)
-        
 
-        
+
 
 class WaveAudioSource(AudioSource):
     """
@@ -316,7 +313,6 @@
         
     
     def read(self, size):
-        
         if self._audio_stream is None:
             raise IOError("Stream is not open")
         else:
@@ -366,7 +362,6 @@
             
     
     def read(self, size):
-        
         if self._audio_stream is None:
             raise IOError("Stream is not open")
         
@@ -422,8 +417,6 @@
     def __init__(self, sampling_rate = DEFAULT_SAMPLE_RATE,
                  sample_width = DEFAULT_SAMPLE_WIDTH,
                  channels = DEFAULT_NB_CHANNELS):
-        
-    
         if not sample_width in (1, 2, 4):
             raise ValueError("Sample width must be one of: 1, 2 or 4 (bytes)")
         
@@ -446,7 +439,6 @@
             
         self.stream.stop_stream()
     
-        
     def  stop(self):
         if not self.stream.is_stopped():
             self.stream.stop_stream()
@@ -463,10 +455,9 @@
         
 
 def from_file(filename):
-    
     """
     Create an `AudioSource` object using the audio file specified by `filename`.
-    The appropriate `AudioSource` class is guessed from file's extension.
+    The appropriate :class:`AudioSource` class is guessed from file's extension.
     
     :Parameters:
     
--- a/doc/apitutorial.rst	Fri Dec 11 21:23:08 2015 +0100
+++ b/doc/apitutorial.rst	Sun Mar 06 14:57:03 2016 +0100
@@ -428,7 +428,7 @@
 brief noise that occurs within the leading silence. We certainly do want our tokenizer 
 to stop at this point and considers whatever it comes after as a useful signal.
 To force the tokenizer to ignore that brief event we use two other parameters `init_min`
-ans `init_max_silence`. By `init_min` = 3 and `init_max_silence` = 1 we tell the tokenizer
+and `init_max_silence`. By `init_min` = 3 and `init_max_silence` = 1 we tell the tokenizer
 that a valid event must start with at least 3 noisy windows, between which there
 is at most 1 silent window.
 
--- a/doc/conf.py	Fri Dec 11 21:23:08 2015 +0100
+++ b/doc/conf.py	Sun Mar 06 14:57:03 2016 +0100
@@ -112,19 +112,19 @@
 
 # The theme to use for HTML and HTML Help pages.  See the documentation for
 # a list of builtin themes.
-#html_theme = 'sphinxdoc'
+html_theme = 'sphinxdoc'
 
 
 # on_rtd is whether we are on readthedocs.org
 import os
 on_rtd = os.environ.get('READTHEDOCS', None) == 'True'
 
-
+"""
 if not on_rtd:  # only import and set the theme if we're building docs locally
     import sphinx_rtd_theme
     html_theme = 'sphinx_rtd_theme'
     html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]
-
+"""
 
 # Theme options are theme-specific and customize the look and feel of a theme
 # further.  For a list of options available for each theme, see the