Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error for each supported audio file type #11

Open
darcy-clark opened this issue Dec 1, 2017 · 5 comments
Open

Error for each supported audio file type #11

darcy-clark opened this issue Dec 1, 2017 · 5 comments

Comments

@darcy-clark
Copy link

darcy-clark commented Dec 1, 2017

I have tried running functional audio files for a .flac, .mp3 and .wav but receive different errors for each one. My code is pretty much the same for the 3 different tests:

package main

import(
  "fmt"
  "time"
  "os"
  "github.com/faiface/beep/<file type>"
  "github.com/faiface/beep/speaker"
)

func main() {
  openFile, openFileErr := os.Open("<path/to/file>")
  if openFileErr != nil {
    fmt.Println("FILE OPEN ERROR", openFileErr)
    return
  }
  streamer, format, streamerErr := <file type>.Decode(openFile)
  if streamerErr != nil {
    fmt.Println("AUDIO STREAMER ERROR", streamerErr)
    return
  }
  speaker.Init(format.SampleRate, format.SampleRate.N(time.Second/10))
  speaker.Play(streamer)
  select{}
}

Expected:
Audio plays normally.

WAV Result:
wav: missing data chunk marker

MP3 Result:
mp3: mp3: only layer3 (want 1; got 3) is supported

Flac Result:
flac: flac.parseStreamInfo: invalid FLAC signature; expected "fLaC", got "RIFF"

Here are the files for your own use:
Flac file
MP3 file
WAV file

All the files are generated by the IBM Watson text-to-speech API and run fine on my machine. All error messages occur within the AUDIO STREAMER ERROR block. Is this a bug? Thanks!

@mewmew
Copy link
Contributor

mewmew commented Dec 21, 2017

The FLAC file you uploaded is in WAV format. Try converting it to FLAC using ffmpeg.

$ file testFlac.flac 
testFlac.flac: RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, mono 22050 Hz

$ hexdump -C testFlac.flac | head
00000000  52 49 46 46 ff ff ff ff  57 41 56 45 66 6d 74 20  |RIFF....WAVEfmt |
00000010  10 00 00 00 01 00 01 00  22 56 00 00 44 ac 00 00  |........"V..D...|
00000020  02 00 10 00 4c 49 53 54  1a 00 00 00 49 4e 46 4f  |....LIST....INFO|
00000030  49 53 46 54 0e 00 00 00  4c 61 76 66 35 37 2e 37  |ISFT....Lavf57.7|
00000040  31 2e 31 30 30 00 64 61  74 61 ff ff ff ff 1d 00  |1.100.data......|
00000050  0c 00 06 00 fd ff fa ff  f8 ff f8 ff f2 ff ed ff  |................|
00000060  ea ff dd ff d9 ff dd ff  dd ff e0 ff e6 ff f7 ff  |................|
00000070  00 00 0a 00 0d 00 0d 00  11 00 1a 00 2a 00 34 00  |............*.4.|
00000080  40 00 47 00 45 00 3a 00  1f 00 09 00 00 00 ef ff  |@.G.E.:.........|
00000090  e3 ff cf ff bf ff b7 ff  be ff bf ff bc ff ba ff  |................|

$ ffmpeg -i testFlac.flac out.flac

$ file out.flac
out.flac: FLAC audio bitstream data, 16 bit, mono, 22.05 kHz, 31922 samples

$ hexdump -C out.flac | head
00000000  66 4c 61 43 00 00 00 22  09 00 09 00 00 00 0b 00  |fLaC..."........|
00000010  0b a8 05 62 20 f0 00 00  7c b2 af 3c 8f ff 27 89  |...b ...|..<..'.|
00000020  07 c6 6f 4f 7e 04 b7 51  2b 58 04 00 00 2e 0d 00  |..oO~..Q+X......|
00000030  00 00 4c 61 76 66 35 37  2e 38 33 2e 31 30 30 01  |..Lavf57.83.100.|
00000040  00 00 00 15 00 00 00 65  6e 63 6f 64 65 72 3d 4c  |.......encoder=L|
00000050  61 76 66 35 37 2e 38 33  2e 31 30 30 81 00 20 00  |avf57.83.100.. .|
00000060  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00002060  ff f8 46 08 00 d9 4e 00  1d 00 0c 00 06 ff fd ff  |..F...N.........|
00002070  fa ff f8 ff f8 ff f2 e6  b4 c5 ce 44 1c 2b d8 17  |...........D.+..|

@mewmew
Copy link
Contributor

mewmew commented Dec 21, 2017

That being said, the default FLAC encoding of ffmpeg, after converting the WAV file you provided, is 16 bits-per-sample with 1 channel. At the present, the beep/flac library is not capable of decoding that. However the fix is easy. I may look into it.

$ go run foo.go
panic: support for 16 bits-per-sample and 1 channels combination not yet implemented

Cheers,
/u

@mewmew
Copy link
Contributor

mewmew commented Dec 21, 2017

There we go. With PR #12, the code you submitted works for FLAC files (after having converted the original WAV file to a FLAC file, as outlined below).

ffmpeg -i input.wav out.flac

Cheers,
/u

@mewmew
Copy link
Contributor

mewmew commented Dec 21, 2017

A side note, the test files you linked to are identical. Are these the same files you used on your system?

$ md5sum testMp31.mp3 testWav1.wav testFlac.flac 
4abc5838291789b778745c6b3b9a4ed6  testMp31.mp3
4abc5838291789b778745c6b3b9a4ed6  testWav1.wav
4abc5838291789b778745c6b3b9a4ed6  testFlac.flac

@mewmew
Copy link
Contributor

mewmew commented Dec 21, 2017

A quick hexdump of the WAV sample you uploaded reveals that it contains metadata not yet supported by the beep/wav decoding library. Specifically the unannotated hex-dump in the middle is not yet supported. @faiface, do you know of a WAV spec where this is specified? I checked wiki and the some of its refs, but could not find the definition of some of these chunks, e.g. LIST, INFO etc.

Edit: ok, I did a quick check. Missed that wiki does indeed mention the LIST chunk.

RiffMark:      52 49 46 46 // "RIFF"
FileSize:      ff ff ff ff
WaveMark:      57 41 56 45 // "WAVE"
FmtMark:       66 6d 74 20 // "fmt "
FormatSize:    10 00 00 00
FormatType:    01 00
NumChans:      01 00
SampleRate:    22 56 00 00
ByteRate:      44 ac 00 00
BytesPerFrame: 02 00
BitsPerSample: 10 00

            4c 49 53 54 1a 00 00 00 49 4e 46 4f  |    LIST....INFO|
49 53 46 54 0e 00 00 00 4c 61 76 66 35 37 2e 37  |ISFT....Lavf57.7|
31 2e 31 30 30 00                                |1.100.          |

DataMark:      64 61 74 61 // "data"
DataSize:      ff ff ff ff

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants