Skip to content

no transcription results #369

@lukeewin

Description

@lukeewin

os: windows 11
faster whisper: 0.7.0

When the input audio is an np array, there are no error messages, but there are also no transcription results. Through my debugging, I found that the statement for segment in segments: was not executed

this is my code:

import asyncio
import io
import json
import wave
import pyaudio
import websockets
from faster_whisper import WhisperModel
import os
import numpy as np
import sounddevice as sd


stream = sd.OutputStream(samplerate=16000, channels=1)

stream.start()

os.environ["KMP_DUPLICATE_LIB_OK"]  =  "TRUE"


def initWhisperModel():
    model_size = "tiny"
    model = WhisperModel(model_size, device="cpu", compute_type="int8", num_workers=8, local_files_only=True)
    return model

def write_wav(out_path, audio_data):
    wf = wave.open(out_path, 'wb')
    wf.setnchannels(1)
    p = pyaudio.PyAudio()
    wf.setsampwidth(p.get_sample_size(pyaudio.paInt16))
    wf.setframerate(16000)
    wf.writeframes(audio_data)
    wf.close()

async def process_audio_data(audio_frame, websocket):
    # print(type(audio_frame))
    # print(audio_frame)
    segments, info = model.transcribe(audio_frame, beam_size=5, language="zh", initial_prompt="转录成简体中文",
                                      vad_filter=True,
                                      vad_parameters=dict(min_silence_duration_ms=500))
    # print(type(segments))
    # print(segments)
    for segment in segments:
        print("11112")
        message = json.dumps({"text": segment.text})
        await websocket.send(message)

async def receive_audio_data(websocket, path):
    try:
        async for message in websocket:
            if isinstance(message, bytes):
                audio_data = np.frombuffer(message, dtype=np.float32)
                await process_audio_data(audio_data, websocket)

    except websockets.ConnectionClosed:
        print("WebSocket connection closed.")

model = initWhisperModel()
start_server = websockets.serve(receive_audio_data, 'localhost', 8765, subprotocols=["binary"], ping_interval=None)
asyncio.get_event_loop().run_until_complete(start_server)
asyncio.get_event_loop().run_forever()

Here is the console output when I ran the code.

D:\Software\Anaconda\envs\RealTime\lib\site-packages\numpy\_distributor_init.py:30: UserWarning: loaded more than 1 DLL from .libs:
D:\Software\Anaconda\envs\RealTime\lib\site-packages\numpy\.libs\libopenblas64__v0.3.21-gcc_10_3_0.dll
D:\Software\Anaconda\envs\RealTime\lib\site-packages\numpy\.libs\libopenblas64__v0.3.23-gcc_10_3_0.dll
  warnings.warn("loaded more than 1 DLL from .libs:"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions