diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-26 18:46:15 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-26 18:46:15 +0000 |
commit | 50fab53bddb2c3cb24d5682c913a03226ccf49ef (patch) | |
tree | bb04af83ca5f2be010e32c2e10cfd245117a4847 /content/browser/speech/audio_encoder.h | |
parent | 5c557f37629dc12dfd99e8fb55c235c8c46a8098 (diff) | |
download | chromium_src-50fab53bddb2c3cb24d5682c913a03226ccf49ef.zip chromium_src-50fab53bddb2c3cb24d5682c913a03226ccf49ef.tar.gz chromium_src-50fab53bddb2c3cb24d5682c913a03226ccf49ef.tar.bz2 |
Move core pieces of speech from chrome to content.
TBR=satish
Review URL: http://codereview.chromium.org/6591024
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@76165 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser/speech/audio_encoder.h')
-rw-r--r-- | content/browser/speech/audio_encoder.h | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/content/browser/speech/audio_encoder.h b/content/browser/speech/audio_encoder.h new file mode 100644 index 0000000..c70bfd0 --- /dev/null +++ b/content/browser/speech/audio_encoder.h @@ -0,0 +1,59 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CONTENT_BROWSER_SPEECH_AUDIO_ENCODER_H_ +#define CONTENT_BROWSER_SPEECH_AUDIO_ENCODER_H_ + +#include <list> +#include <string> + +#include "base/basictypes.h" + +namespace speech_input { + +// Provides a simple interface to encode raw audio using the various speech +// codecs. +class AudioEncoder { + public: + enum Codec { + CODEC_FLAC, + CODEC_SPEEX, + }; + + static AudioEncoder* Create(Codec codec, + int sampling_rate, + int bits_per_sample); + + virtual ~AudioEncoder(); + + // Encodes each frame of raw audio in |samples| to the internal buffer. Use + // |GetEncodedData| to read the result after this call or when recording + // completes. + virtual void Encode(const short* samples, int num_samples) = 0; + + // Finish encoding and flush any pending encoded bits out. + virtual void Flush() = 0; + + // Copies the encoded audio to the given string. Returns true if the output + // is not empty. + bool GetEncodedData(std::string* encoded_data); + + const std::string& mime_type() { return mime_type_; } + + protected: + AudioEncoder(const std::string& mime_type); + + void AppendToBuffer(std::string* item); + + private: + // Buffer holding the recorded audio. Owns the strings inside the list. + typedef std::list<std::string*> AudioBufferQueue; + AudioBufferQueue audio_buffers_; + std::string mime_type_; + DISALLOW_COPY_AND_ASSIGN(AudioEncoder); +}; + +} // namespace speech_input + +#endif // CONTENT_BROWSER_SPEECH_AUDIO_ENCODER_H_ |