如何在无限流式识别期间记录文件?

时间:2019-11-09 16:50:06

标签: google-cloud-speech

我想在使用Java进行无限流识别期间录制语音

我试图录制其他线程的声音,但是重复的音频线会导致严重错误

这是我的语音记录代码

Runnable r = new Runnable() {

    @Override
    public void run() {
        try {
            AudioFormat format = getAudioFormat();
            DataLine.Info info = new DataLine.Info(TargetDataLine.class, format);

            // checks if system supports the data line
            if (!AudioSystem.isLineSupported(info)) {
                System.out.println("Line not supported");
                System.exit(0);
            }
            line = (TargetDataLine) AudioSystem.getLine(info);
            line.open(format);
            line.start(); // start capturing
            System.out.println("Start capturing...");

            AudioInputStream ais = new AudioInputStream(line);

            System.out.println("Start recording...");

            // start recording
            AudioSystem.write(ais, fileType, wavFile);

        } catch (LineUnavailableException ex) {
            ex.printStackTrace();
        } catch (IOException ioe) {
            ioe.printStackTrace();
        }

    }
};

这是我的语音记录设置代码      AudioFormat getAudioFormat() { float sampleRate = 16000; int sampleSizeInBits = 16; int channels = 1; boolean signed = true; boolean bigEndian = false; AudioFormat format = new AudioFormat(sampleRate, sampleSizeInBits, channels, signed, bigEndian); return format; } javax.sound.sampled.LineUnavailableException:格式为PCM_SIGNED 16000.0 Hz的行,16位,单声道,2字节/帧,不支持little-endian。 2019年11月10日1:44:31 io.grpc.internal.ManagedChannelImpl $ 1 uncaughtException 说明:[io.grpc.internal.ManagedChannelImpl-1] SynchronizationContext中未捕获的异常。恐慌! java.util.concurrent.RejectedExecutionException:任务java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask@40f280a9从java.util.concurrent.ScheduledThreadPoolExecutor@743ef0f拒绝了[已终止,池大小= 0,活动线程= 0,排队的任务= 0,已完成任务= 0]     在java.util.concurrent.ThreadPoolExecutor $ AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:2063)     在java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:830)     在java.util.concurrent.ScheduledThreadPoolExecutor.delayedExecute(ScheduledThreadPoolExecutor.java:326)     在java.util.concurrent.ScheduledThreadPoolExecutor.schedule(ScheduledThreadPoolExecutor.java:533)     在java.util.concurrent.ScheduledThreadPoolExecutor.execute(ScheduledThreadPoolExecutor.java:622)     在io.grpc.internal.DelayedClientTransport.reprocess(DelayedClientTransport.java:302)     在io.grpc.internal.ManagedChannelImpl.updateSubchannelPicker(ManagedChannelImpl.java:742)     在io.grpc.internal.ManagedChannelImpl.access $ 5200(ManagedChannelImpl.java:97)     在io.grpc.internal.ManagedChannelImpl $ LbHelperImpl $ 1UpdateBalancingState.run(ManagedChannelImpl.java:1113)     在io.grpc.SynchronizationContext.drain(SynchronizationContext.java:101)     在io.grpc.internal.InternalSubchannel $ TransportListener.transportReady(InternalSubchannel.java:574)     在io.grpc.netty.shaded.io.grpc.netty.ClientTransportLifecycleManager.notifyReady(ClientTransportLifecycleManager.java:43)     在io.grpc.netty.shaded.io.grpc.netty.NettyClientHandler $ FrameListener.onSettingsRead(NettyClientHandler.java:759)     在io.grpc.netty.shaded.io.netty.handler.codec.http2.DefaultHttp2ConnectionDecoder $ FrameReadListener.onSettingsRead(DefaultHttp2ConnectionDecoder.java:419)     在io.grpc.netty.shaded.io.netty.handler.codec.http2.DefaultHttp2ConnectionDecoder $ PrefaceFrameListener.onSettingsRead(DefaultHttp2ConnectionDecoder.java:637)     在io.grpc.netty.shaded.io.netty.handler.codec.http2.Http2InboundFrameLogger $ 1.onSettingsRead(Http2InboundFrameLogger.java:93)     在io.grpc.netty.shaded.io.netty.handler.codec.http2.DefaultHttp2FrameReader.readSettingsFrame(DefaultHttp2FrameReader.java:542)     在io.grpc.netty.shaded.io.netty.handler.codec.http2.DefaultHttp2FrameReader.processPayloadState(DefaultHttp2FrameReader.java:263)     在io.grpc.netty.shaded.io.netty.handler.codec.http2.DefaultHttp2FrameReader.readFrame(DefaultHttp2FrameReader.java:160)     在io.grpc.netty.shaded.io.netty.handler.codec.http2.Http2InboundFrameLogger.readFrame(Http2InboundFrameLogger.java:41)     在io.grpc.netty.shaded.io.netty.handler.codec.http2.DefaultHttp2ConnectionDecoder.decodeFrame(DefaultHttp2ConnectionDecoder.java:118)     在io.grpc.netty.shaded.io.netty.handler.codec.http2.Http2ConnectionHandler $ FrameDecoder.decode(Http2ConnectionHandler.java:390)     在io.grpc.netty.shaded.io.netty.handler.codec.http2.Http2ConnectionHandler $ PrefaceDecoder.decode(Http2ConnectionHandler.java:254)     在io.grpc.netty.shaded.io.netty.handler.codec.http2.Http2ConnectionHandler.decode(Http2ConnectionHandler.java:450)     在io.grpc.netty.shaded.io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:502)     在io.grpc.netty.shaded.io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:441)     在io.grpc.netty.shaded.io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:278)     在io.grpc.netty.shaded.io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)     在io.grpc.netty.shaded.io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)     在io.grpc.netty.shaded.io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)     在io.grpc.netty.shaded.io.netty.handler.ssl.SslHandler.unwrap(SslHandler.java:1429)     在io.grpc.netty.shaded.io.netty.handler.ssl.SslHandler.decodeJdkCompatible(SslHandler.java:1199)     在io.grpc.netty.shaded.io.netty.handler.ssl.SslHandler.decode(SslHandler.java:1243)     在io.grpc.netty.shaded.io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:502)     在io.grpc.netty.shaded.io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:441)     在io.grpc.netty.shaded.io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:278)     在io.grpc.netty.shaded.io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)     在io.grpc.netty.shaded.io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)     在io.grpc.netty.shaded.io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)     在io.grpc.netty.shaded.io.netty.channel.DefaultChannelPipeline $ HeadContext.channelRead(DefaultChannelPipeline.java:1434)     在io.grpc.netty.shaded.io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)     在io.grpc.netty.shaded.io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)     在io.grpc.netty.shaded.io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:965)     在io.grpc.netty.shaded.io.netty.channel.nio.AbstractNioByteChannel $ NioByteUnsafe.read(AbstractNioByteChannel.java:163)     在io.grpc.netty.shaded.io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:644)     在io.grpc.netty.shaded.io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:579)     在io.grpc.netty.shaded.io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:496)     在io.grpc.netty.shaded.io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:458)     在io.grpc.netty.shaded.io.netty.util.concurrent.SingleThreadEventExecutor $ 5.run(SingleThreadEventExecutor.java:897)     在io.grpc.netty.shaded.io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)     在java.lang.Thread.run(Thread.java:748)

0 个答案:

没有答案