发生异常:错误 mpg123_seek:RVA 模式无效.(代码 12) [英] Exception has occurred: error mpg123_seek: Invalid RVA mode. (code 12)

查看:1281
本文介绍了发生异常:错误 mpg123_seek:RVA 模式无效.(代码 12)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 sounddevice 录制音频,我想通过 pygame 通过虚拟音频电缆播放它,我不断收到此错误 发生异常:错误 mpg123_seek:无效的 RVA 模式.(代码 12)

I am recording audio using sounddevice and I want to play it through a virtual audio cable through pygame, I keep receiving this error Exception has occurred: error mpg123_seek: Invalid RVA mode. (code 12)

我的代码如下:

import sounddevice as sd
from scipy.io.wavfile import write
import random
import pygame
import time

pygame.init()
pygame.mixer.init(devicename='CABLE Input (VB-Audio Virtual Cable)')

fs = 44100  # Sample rate
seconds = 00.1  # Duration of recording


def main():
    for x in range(10000):
        number = random.randint(1,9999999)


        myrecording = sd.rec(int(seconds * fs), samplerate=fs, channels=2)
        sd.wait()  # Wait until recording is finished
        write(f'output/output{str(number)}.mp3', fs, myrecording)  # Save as WAV file `

        # PLAY MIC SOUND HERE
        pygame.mixer.music.load(f'output/output{str(number)}.mp3') #Load the mp3  
        pygame.mixer.music.play() #Play it
        time.sleep(00.1)

main()

感谢任何帮助.

推荐答案

有几个问题.

第一个是 scipi.io.wavefile.write() 只写一个未压缩的 WAV 文件(参考:https://docs.scipy.org/doc/scipy/reference/generated/scipy.io.wavfile.write.html).您可以将其命名为 .mp3,但它不会以这种方式压缩.

The first is that scipi.io.wavefile.write() only writes an uncompressed WAV file (ref: https://docs.scipy.org/doc/scipy/reference/generated/scipy.io.wavfile.write.html ). You might name it .mp3, but it's not compressed that way.

下一个问题是 pygame.mixer.music 不会 .load() 未压缩的 WAV 文件.所以……怎么办……

The next issue is that pygame.mixer.music will not .load() uncompressed WAV files. So... what to do...

一种解决方法是使用基础 pygame.mixer,它很乐意加载未压缩的 WAV.虽然我没有CABLE Input(VB-Audio Virtual Cable)"设备,但我确实得到了一个不错的静音文件,我用声音编辑程序 Audacity 对其进行了验证,这似乎可以正常播放.

One work-around is to use the base pygame.mixer, which is happy to load uncompressed WAV. And while I don't have an 'CABLE Input (VB-Audio Virtual Cable)' device, I do get a nice file of silence, which I validated with the sound-editing program Audacity, and this seems to play OK.

import sounddevice as sd
from scipy.io.wavfile import write
import pygame
import time
import random

pygame.init()
pygame.mixer.init(devicename='CABLE Input (VB-Audio Virtual Cable)')

fs = 44100  # Sample rate
seconds = 00.1  # Duration of recording


def main():
    for x in range(10000):
        number = random.randint(1,9999999)

        myrecording = sd.rec(int(seconds * fs), samplerate=fs, channels=2)
        sd.wait()  # Wait until recording is finished

        filename = f'output/output{str(number)}.wav'
        write(filename, fs, myrecording)  # Save as uncompressed WAV file 

        # PLAY MIC SOUND HERE
        print( "Playing ["  + filename + "]" )

        #pygame.mixer.music.load(filename) #Load the wav
        #pygame.mixer.music.play() #Play it
        #while ( pygame.mixer.music.get_busy() ):  # wait for the sound to end
        #    time.sleep(00.1)

        sound = pygame.mixer.Sound(filename) #Load the wav
        sound.play() #Play it
        while ( pygame.mixer.get_busy() ):  # wait for the sound to end
            time.sleep(00.1)

main()

这篇关于发生异常:错误 mpg123_seek:RVA 模式无效.(代码 12)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆