how to get time of key held down?

e.g how do i know the time, for which I have pressed spacebar… I want to play a sound when user presses space bar for 2 seconds… here is my code:

if (Input.GetKeyDown (“space”)) {

	flying.Play ();	 // i want to play this sound after two seconds of spacebar press	
	jump.Play ();
}

This code finally worked for me…

public float downTime, upTime, pressTime = 0;
public float countDown = 2.0f;
public bool ready = false;

		void Update ()
		{
				if (Input.GetKeyDown (KeyCode.Space) && ready == false) {
						downTime = Time.time;
						pressTime = downTime + countDown;
						ready = true;
				}
				if (Input.GetKeyUp (KeyCode.Space)) {
						ready = false;
				}
				if (Time.time >= pressTime && ready == true) {
						ready = false;
						audio.Play ();
				}	
		}

using UnityEngine;
using System.Collections;

public class keyTimer : MonoBehaviour {
	float timePressed = 0f;
	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
		keyPressedTimer();

	}


	
	void keyPressedTimer()
	{
		if(Input.GetKeyDown(KeyCode.Space))
		{
			timePressed = Time.time;
		}
		
		if(Input.GetKeyUp(KeyCode.Space))
		{
			timePressed = Time.time - timePressed;
			Debug.Log("Pressed for : " + timePressed + " Seconds");
		}
	}
}

Try this.

public var keyTimer : float = 0; //Our timer
public var keyLength : float = 2; //The duration needed to trigger the function
public var isKeyActive : boolean = false;

function Update() {

	//Initial key press
	if (Input.GetKeyDown(KeyCode.Space) && !isKeyActive) {
	
		//Get the timestamp
		keyTimer = Time.time;
		isKeyActive = true;
	
		}
	
	//Key currently being held down
	if (Input.GetKey(KeyCode.Space) && isKeyActive) {
	
		//Check is time elapsed is greater than keyLength
		if (Time.time - keyTimer > keyLength) {
			PlaySound();
			isKeyActive = false;
			}
	
		}
	
	//Key released
	//This will not execute if the button is held (isKeyActive is false)
	if (Input.GetKeyUp(KeyCode.Space) && isKeyActive) {
	
		//Do something else
		isKeyActive = false;
	
		}

	}