index.d.ts 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. declare module 'opusscript' {
  2. /**
  3. * Opus application type
  4. */
  5. enum OpusApplication {
  6. /**
  7. * Voice Over IP
  8. */
  9. VOIP = 2048,
  10. /**
  11. * Audio
  12. */
  13. AUDIO = 2049,
  14. /**
  15. * Restricted Low-Delay
  16. */
  17. RESTRICTED_LOWDELAY = 2051
  18. }
  19. enum OpusError {
  20. "OK" = 0,
  21. "Bad argument" = -1,
  22. "Buffer too small" = -2,
  23. "Internal error" = -3,
  24. "Invalid packet" = -4,
  25. "Unimplemented" = -5,
  26. "Invalid state" = -6,
  27. "Memory allocation fail" = -7
  28. }
  29. /**
  30. * Valid audio sampling rates
  31. */
  32. type VALID_SAMPLING_RATES = 8000 | 12000 | 16000 | 24000 | 48000;
  33. /**
  34. * Maximum bytes in a frame
  35. */
  36. type MAX_FRAME_SIZE = 2880;
  37. /**
  38. * Maximum bytes in a packet
  39. */
  40. type MAX_PACKET_SIZE = 3828;
  41. class OpusScript {
  42. /**
  43. * Different Opus application types
  44. */
  45. static Application: typeof OpusApplication;
  46. /**
  47. * Opus Error codes
  48. */
  49. static Error: typeof OpusError;
  50. /**
  51. * Array of sampling rates that Opus can use
  52. */
  53. static VALID_SAMPLING_RATES: [8000, 12000, 16000, 24000, 48000];
  54. /**
  55. * The maximum size (in bytes) to send in a packet
  56. */
  57. static MAX_PACKET_SIZE: MAX_PACKET_SIZE;
  58. /**
  59. * Create a new Opus en/decoder
  60. */
  61. constructor(samplingRate: VALID_SAMPLING_RATES, channels?: number, application?: OpusApplication);
  62. /**
  63. * Encode a buffer into Opus
  64. */
  65. encode(buffer: Buffer, frameSize: number): Buffer;
  66. /**
  67. * Decode an opus buffer
  68. */
  69. decode(buffer: Buffer): Buffer;
  70. encoderCTL(ctl: number, arg: number): void;
  71. decoderCTL(ctl: number, arg: number): void;
  72. /**
  73. * Delete the opus object
  74. */
  75. delete(): void;
  76. }
  77. export = OpusScript;
  78. }