Azure-Samples / cognitive-services-speech-sdk

Sample code for the Microsoft Cognitive Services Speech SDK
MIT License
2.69k stars 1.79k forks source link

Hugging Face Runtime error: Failed to initialize platform (azure-c-shared). Error: 2176 #2397

Open aikitty123 opened 1 month ago

aikitty123 commented 1 month ago

Hello, I'm trying to create a service on Hugging Face but when I try to use Microsoft Speech services I get this error:

Error: "Runtime error: Failed to initialize platform (azure-c-shared). Error: 2176".

Does anyone know how to fix this on Hugging Face? Please feel free to ask me for any relevant information. I'm not sure what would be helpful.

Kerry-LinZhang commented 1 month ago

Hi @aikitty123 shall we have more details for this problem, for example the repro steps? How did you attempt to integrate Microsoft Speech services? Did you use a specific SDK or API? Which programming language are you using? And which version of Microsoft Speech services are you working with? Have you followed any official documentation or guides from Hugging Face for integrating the service? If so, could you provide the relevant links? Have you tried reconfiguring your environment or reinstalling dependencies to address this issue? If so, could you describe the steps you've taken?

aikitty123 commented 1 month ago

Thank you for your response. Here are the details for the problem I am encountering:

  1. Integration Approach: I attempted to integrate Microsoft Speech services using the Azure Cognitive Services Speech SDK. Specifically, I used the Python SDK for speech services.

  2. Programming Language and SDK Version: I am using Python as the programming language. Initially, I tried using the latest version of the Azure Cognitive Services Speech SDK using Speech SDK 1.30.1, which I specified in the requirements.txt file.

  3. Documentation and Guides: I tried to follow the official documentation from Microsoft for the Azure Cognitive Services Speech SDK. I also referred to general Hugging Face Spaces documentation for deploying applications but didn't find specific guides for integrating Microsoft Speech services on Hugging Face.

Here are the links to the documentation I followed:

  1. Steps Taken to Reconfigure Environment:
    • Specified the required dependencies in the requirements.txt file, using the latest version.
    • Verified the compatibility of the specified versions with Hugging Face Spaces.
    • Updated the app.py file to match the configurations suggested by the official Microsoft documentation.
    • Ensured that unnecessary dependencies were removed from the requirements.txt file to avoid conflicts.

Despite these steps, I continue to encounter the "Runtime error: Failed to initialize platform (azure-c-shared). Error: 2176" error.

I appreciate any any further guidance or suggestions to resolve this issue.

Thank you for your assistance.

Best regards, aikitty123

P.S. Here is my app.py file, if that helps:



import gradio as gr
import azure.cognitiveservices.speech as speechsdk

def assess_pronunciation(audio_file, reference_text):
    try:
        # Configure Azure Speech Service
        speech_key = "MYKEY"
        service_region = "westus"
        speech_config = speechsdk.SpeechConfig(subscription=speech_key, region=service_region)

        # Set up the audio configuration
        audio_config = speechsdk.audio.AudioConfig(filename=audio_file)

        # Create pronunciation assessment config
        pronunciation_config = speechsdk.PronunciationAssessmentConfig(
            reference_text=reference_text,
            grading_system=speechsdk.PronunciationAssessmentGradingSystem.HundredMark,
            granularity=speechsdk.PronunciationAssessmentGranularity.Phoneme
        )

        # Create the recognizer
        recognizer = speechsdk.SpeechRecognizer(speech_config=speech_config, audio_config=audio_config)
        pronunciation_config.apply_to(recognizer)

        # Recognize speech and assess pronunciation
        result = recognizer.recognize_once()

        # Debug information
        print(f"Recognition result reason: {result.reason}")

        if result.reason == speechsdk.ResultReason.RecognizedSpeech:
            pronunciation_result = speechsdk.PronunciationAssessmentResult(result)

            # Extract and format the results
            accuracy_score = pronunciation_result.accuracy_score
            fluency_score = pronunciation_result.fluency_score
            completeness_score = pronunciation_result.completeness_score
            prosody_score = pronunciation_result.prosody_score

            return {
                "Accuracy": accuracy_score,
                "Fluency": fluency_score,
                "Completeness": completeness_score,
                "Prosody": prosody_score
            }
        elif result.reason == speechsdk.ResultReason.NoMatch:
            print("NOMATCH: Speech could not be recognized.")
            return {"Error": "Speech could not be recognized. Please try again with a clearer audio."}
        elif result.reason == speechsdk.ResultReason.Canceled:
            cancellation_details = speechsdk.CancellationDetails(result)
            print(f"CANCELED: Reason={cancellation_details.reason}")
            print(f"CANCELED: ErrorDetails={cancellation_details.error_details}")
            return {"Error": f"Speech recognition canceled: {cancellation_details.error_details}"}
    except Exception as e:
        print(f"An error occurred: {str(e)}")
        return {"Error": f"An unexpected error occurred: {str(e)}"}

# Create Gradio interface
interface = gr.Interface(
    fn=assess_pronunciation,
    inputs=[
        gr.Audio(type="filepath"),  # Audio input
        gr.Textbox(label="Reference Text", placeholder="Enter the reference text you are pronouncing")  # Reference text input
    ],
    outputs="json",
    title="Chinese Pronunciation Checker"
)

if __name__ == "__main__":
    interface.launch()
github-actions[bot] commented 2 weeks ago

This item has been open without activity for 19 days. Provide a comment on status and remove "update needed" label.

aikitty123 commented 2 weeks ago

Does anyone have any ideas?