Ejemplo n.º 1
0
def WriteAudioSeries(writer, tag, n_audio=1):
  """Write a few dummy audio clips to writer."""
  step = 0
  session = session_lib.Session()

  min_frequency_hz = 440
  max_frequency_hz = 880
  sample_rate = 4000
  duration_frames = sample_rate * 0.5  # 0.5 seconds.
  frequencies_per_run = 1
  num_channels = 2

  p = array_ops.placeholder("float32", (frequencies_per_run, duration_frames,
                                        num_channels))
  s = logging_ops.audio_summary(tag, p, sample_rate)

  for _ in xrange(n_audio):
    # Generate a different frequency for each channel to show stereo works.
    frequencies = np.random.random_integers(
        min_frequency_hz,
        max_frequency_hz,
        size=(frequencies_per_run, num_channels))
    tiled_frequencies = np.tile(frequencies, (1, duration_frames))
    tiled_increments = np.tile(
        np.arange(0, duration_frames),
        (num_channels, 1)).T.reshape(1, duration_frames * num_channels)
    tones = np.sin(2.0 * np.pi * tiled_frequencies * tiled_increments /
                   sample_rate)
    tones = tones.reshape(frequencies_per_run, duration_frames, num_channels)

    summ = session.run(s, feed_dict={p: tones})
    writer.add_summary(summ, step)
    step += 20
  session.close()
Ejemplo n.º 2
0
 def testAudioSummary(self):
   with self.cached_session():
     c = constant_op.constant(3.0)
     s = logging_ops.audio_summary('tag', c, sample_rate=8000)
     self.assertEqual(s.op.type, u'AudioSummaryV2')
Ejemplo n.º 3
0
 def testAudioSummary(self):
     with self.cached_session():
         c = constant_op.constant(3.0)
         s = logging_ops.audio_summary('tag', c, sample_rate=8000)
         self.assertEqual(s.op.type, u'AudioSummaryV2')