0

I am setting up a new ASR server. Audio data is coming from a client, the audio data format is an int16 array (PCM data), and it should be changed to a vector<float> before ASR server engine.

I tried many times, but a compiler error happens like below:

error: invalid conversion from ‘int’ to  kaldi::MatrixResizeType’ [-fpermissive]

error: ‘vector’ was not declared in this scope
    wave_data = vector(std::begin(pcm_bytes), std::end(pcm_bytes)); //testing;

error: missing template arguments before ‘(’ token
    Vector wave_data = Vector(pcm_bytes, pcm_bytes + sizeof(pcm_bytes) / sizeof(pcm_bytes[0])); //testing;

Please tell me how I can change the array to a vector (int16 to float) without compile errors.

My source file:

BaseFloat pcm_bytes[MAX_FRAME_SIZE*CHANNELS*2];
opus_int16 out[MAX_FRAME_SIZE*CHANNELS]; //opus_int16

/* Convert to little-endian ordering. */
for(int i=0; i<CHANNELS*userinfo->asr_session_data->frame_size; i++)
{
  //pcm_byte
  pcm_bytes[2*i]=(BaseFloat)(out[i]&0xFF);
  pcm_bytes[2*i+1]=(BaseFloat)((out[i]>>8)&0xFF);
}
//vector init
Vector<BaseFloat> wave_data(CHANNELS*userinfo->asr_session_data->frame_size,0);
*wave_data = vector(std::begin(pcm_bytes), std::end(pcm_bytes));* //testing;  -> **error happend this line**    

My header file for the vector:

template<typename Real>
class Vector: public VectorBase<Real> {
 public:
  /// Constructor that takes no arguments.  Initializes to empty.
  Vector(): VectorBase<Real>() {}

  /// Constructor with specific size.  Sets to all-zero by default
  /// if set_zero == false, memory contents are undefined.
  explicit Vector(const MatrixIndexT s,
                  MatrixResizeType resize_type = kSetZero)
      : VectorBase<Real>() {  Resize(s, resize_type);  }

  /// Copy constructor from CUDA vector
  /// This is defined in ../cudamatrix/cu-vector.h
  template<typename OtherReal>
  explicit Vector(const CuVectorBase<OtherReal> &cu);

  /// Copy constructor.  The need for this is controversial.
  Vector(const Vector<Real> &v) : VectorBase<Real>()  { //  (cannot be explicit)
    Resize(v.Dim(), kUndefined);
    this->CopyFromVec(v);
  }

  /// Copy-constructor from base-class, needed to copy from SubVector.
  explicit Vector(const VectorBase<Real> &v) : VectorBase<Real>() {
    Resize(v.Dim(), kUndefined);
    this->CopyFromVec(v);
  }

  /// Type conversion constructor.
  template<typename OtherReal>
  explicit Vector(const VectorBase<OtherReal> &v): VectorBase<Real>() {
    Resize(v.Dim(), kUndefined);
    this->CopyFromVec(v);
  }

// Took this out since it is unsafe : Arnab
//  /// Constructor from a pointer and a size; copies the data to a location
//  /// it owns.
//  Vector(const Real* Data, const MatrixIndexT s): VectorBase<Real>() {
//    Resize(s);
  //    CopyFromPtr(Data, s);
//  }


  /// Swaps the contents of *this and *other.  Shallow swap.
  void Swap(Vector<Real> *other);

  /// Destructor.  Deallocates memory.
  ~Vector() { Destroy(); }

};
3
  • 1
    Is there any reason you are implementing your own vector instead of using std::vector? Commented Aug 19, 2019 at 6:07
  • I got a open source, its not my code but open source use theirs. Commented Aug 19, 2019 at 6:35
  • Okay... How can you access the data in Vector? I guess it's somewhere defined in VectorBase. Commented Aug 19, 2019 at 9:06

1 Answer 1

0

In the line

 *wave_data = vector(std::begin(pcm_bytes), std::end(pcm_bytes));

vector apparently refers to std::vector (probably there's a using namespace std; somewhere - a bad idea, but happens frequently). std::vector is a standard template that requires to specify the element type (e.g. with vector<int>(...) or vector<float>(...).

In the code however no type is specified; that is what the error is saying.

NOTE: C++17 added template parameter deduction for constructors, given the error message looks like your compiler does not support it yet.

Moreover the class Vector (note the capital V) doesn't seem to have a constructor accepting an std::vector, unless the VectorBase has a non-explicit constructor accepting an std::vector.

Sign up to request clarification or add additional context in comments.

1 Comment

@L.F.: added a note about the fact that a C++17 compiler should accept it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.